home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume10 / xlisp21 / part05 < prev    next >
Encoding:
Text File  |  1990-02-26  |  83.4 KB  |  3,279 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Cognos Inc., Ottawa, Canada
  3. subject: v10i092: XLisP 2.1 sources 3a (1/2) / 5
  4. From: garym@cognos.UUCP (Gary Murphy)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 10, Issue 92
  8. Submitted-by: garym@cognos.UUCP (Gary Murphy)
  9. Archive-name: xlisp21/part05
  10.  
  11. #!/bin/sh
  12. # This is a shell archive, meaning:
  13. # 1. Remove everything above the #!/bin/sh line.
  14. # 2. Save the resulting text in a file.
  15. # 3. Execute the file with /bin/sh (not csh) to create the files:
  16. #    xlisp.doc
  17. # This archive created: Sun Feb 18 23:35:09 1990
  18. # By:    Gary Murphy ()
  19. export PATH; PATH=/bin:$PATH
  20. echo shar: extracting "'xlisp.doc'" '(80928 characters)'
  21. if test -f 'xlisp.doc'
  22. then
  23.     echo shar: over-writing existing file "'xlisp.doc'"
  24. fi
  25. sed 's/^X//' << \SHAR_EOF > 'xlisp.doc'
  26. X
  27. X
  28. X
  29. X
  30. X
  31. X
  32. X                         XLISP: An Object-oriented Lisp
  33. X
  34. X                                  Version 2.0
  35. X
  36. X                                February 6, 1988
  37. X
  38. X
  39. X                                       by
  40. X                               David Michael Betz
  41. X                                127 Taylor Road
  42. X                             Peterborough, NH 03458
  43. X
  44. X                             (603) 924-6936 (home)
  45. X                             (603) 882-1599 (BBS)
  46. X
  47. X                   Copyright (c) 1988, by David Michael Betz
  48. X                              All Rights Reserved
  49. X           Permission is granted for unrestricted non-commercial use
  50. X
  51. X
  52. X
  53. X
  54. X
  55. X
  56. X
  57. X
  58. X
  59. X
  60. X
  61. X
  62. X
  63. X
  64. X
  65. X
  66. X
  67. X
  68. X
  69. X
  70. X
  71. X
  72. X
  73. X
  74. X
  75. X
  76. X
  77. X
  78. X
  79. X
  80. X
  81. X
  82. X
  83. X
  84. X
  85. X
  86. X
  87. X
  88. X
  89. X
  90. X
  91. X
  92. X
  93. X
  94. X
  95. X        XLISP                  TABLE OF CONTENTS                  Page 2
  96. X
  97. X
  98. X                               Table of Contents
  99. X
  100. X
  101. X                TABLE OF CONTENTS                        2
  102. X
  103. X                INTRODUCTION                             4
  104. X
  105. X                A NOTE FROM THE AUTHOR                   5
  106. X
  107. X                XLISP COMMAND LOOP                       6
  108. X
  109. X                BREAK COMMAND LOOP                       7
  110. X
  111. X                DATA TYPES                               8
  112. X
  113. X                THE EVALUATOR                            9
  114. X
  115. X                LEXICAL CONVENTIONS                     10
  116. X
  117. X                READTABLES                              11
  118. X
  119. X                LAMBDA LISTS                            12
  120. X
  121. X                OBJECTS                                 14
  122. X
  123. X                SYMBOLS                                 17
  124. X
  125. X                EVALUATION FUNCTIONS                    18
  126. X
  127. X                SYMBOL FUNCTIONS                        19
  128. X
  129. X                PROPERTY LIST FUNCTIONS                 21
  130. X
  131. X                ARRAY FUNCTIONS                         22
  132. X
  133. X                LIST FUNCTIONS                          23
  134. X
  135. X                DESTRUCTIVE LIST FUNCTIONS              26
  136. X
  137. X                PREDICATE FUNCTIONS                     27
  138. X
  139. X                CONTROL CONSTRUCTS                      29
  140. X
  141. X                LOOPING CONSTRUCTS                      31
  142. X
  143. X                THE PROGRAM FEATURE                     32
  144. X
  145. X                DEBUGGING AND ERROR HANDLING            33
  146. X
  147. X                ARITHMETIC FUNCTIONS                    34
  148. X
  149. X                BITWISE LOGICAL FUNCTIONS               36
  150. X
  151. X                STRING FUNCTIONS                        37
  152. X
  153. X
  154. X
  155. X
  156. X
  157. X
  158. X
  159. X
  160. X
  161. X        XLISP                  TABLE OF CONTENTS                  Page 3
  162. X
  163. X
  164. X                CHARACTER FUNCTIONS                     39
  165. X
  166. X                INPUT/OUTPUT FUNCTIONS                  41
  167. X
  168. X                THE FORMAT FUNCTION                     42
  169. X
  170. X                FILE I/O FUNCTIONS                      43
  171. X
  172. X                STRING STREAM FUNCTIONS                 44
  173. X
  174. X                SYSTEM FUNCTIONS                        45
  175. X
  176. X                EXAMPLES                                47
  177. X
  178. X
  179. X
  180. X
  181. X
  182. X
  183. X
  184. X
  185. X
  186. X
  187. X
  188. X
  189. X
  190. X
  191. X
  192. X
  193. X
  194. X
  195. X
  196. X
  197. X
  198. X
  199. X
  200. X
  201. X
  202. X
  203. X
  204. X
  205. X
  206. X
  207. X
  208. X
  209. X
  210. X
  211. X
  212. X
  213. X
  214. X
  215. X
  216. X
  217. X
  218. X
  219. X
  220. X
  221. X
  222. X
  223. X
  224. X
  225. X
  226. X
  227. X        XLISP                     INTRODUCTION                    Page 4
  228. X
  229. X
  230. X        INTRODUCTION
  231. X
  232. X        XLISP is an experimental programming language combining some of
  233. X        the features of Common Lisp with an object-oriented extension
  234. X        capability.  It was implemented to allow experimentation with
  235. X        object-oriented programming on small computers.
  236. X
  237. X        There are currently implementations of XLISP running on the IBM-
  238. X        PC and clones under MS-DOS, on the Macintosh, the Atari-ST and
  239. X        the Amiga.  It is completely written in the programming language
  240. X        'C' and is easily extended with user written built-in functions
  241. X        and classes.  It is available in source form to non-commercial
  242. X        users.
  243. X
  244. X        Many Common Lisp functions are built into XLISP.  In addition,
  245. X        XLISP defines the objects 'Object' and 'Class' as primitives.
  246. X        'Object' is the only class that has no superclass and hence is
  247. X        the root of the class heirarchy tree.  'Class' is the class of
  248. X        which all classes are instances (it is the only object that is
  249. X        an instance of itself).
  250. X
  251. X        This document is a brief description of XLISP.  It assumes some
  252. X        knowledge of LISP and some understanding of the concepts of
  253. X        object-oriented programming.
  254. X
  255. X        I recommend the book "LISP" by Winston and Horn and published by
  256. X        Addison Wesley for learning Lisp.  The first edition of this
  257. X        book is based on MacLisp and the second edition is based on
  258. X        Common Lisp.  XLISP will continue to migrate towards
  259. X        compatibility with Common Lisp.
  260. X
  261. X        You will probably also need a copy of "Common Lisp: The
  262. X        Language" by Guy L. Steele, Jr., published by Digital Press to
  263. X        use as a reference for some of the Common Lisp functions that
  264. X        are described only briefly in this document.
  265. X
  266. X
  267. X
  268. X
  269. X
  270. X
  271. X
  272. X
  273. X
  274. X
  275. X
  276. X
  277. X
  278. X
  279. X
  280. X
  281. X
  282. X
  283. X
  284. X
  285. X
  286. X
  287. X
  288. X
  289. X
  290. X
  291. X
  292. X
  293. X        XLISP                A NOTE FROM THE AUTHOR               Page 5
  294. X
  295. X
  296. X        A NOTE FROM THE AUTHOR
  297. X
  298. X        If you have any problems with XLISP, feel free to contact me for
  299. X        help or advice.  Please remember that since XLISP is available
  300. X        in source form in a high level language, many users have been
  301. X        making versions available on a variety of machines.  If you call
  302. X        to report a problem with a specific version, I may not be able
  303. X        to help you if that version runs on a machine to which I don't
  304. X        have access.  Please have the version number of the version that
  305. X        you are running readily accessible before calling me.
  306. X
  307. X        If you find a bug in XLISP, first try to fix the bug yourself
  308. X        using the source code provided.  If you are successful in fixing
  309. X        the bug, send the bug report along with the fix to me.  If you
  310. X        don't have access to a C compiler or are unable to fix a bug,
  311. X        please send the bug report to me and I'll try to fix it.
  312. X
  313. X        Any suggestions for improvements will be welcomed.  Feel free to
  314. X        extend the language in whatever way suits your needs.  However,
  315. X        PLEASE DO NOT RELEASE ENHANCED VERSIONS WITHOUT CHECKING WITH ME
  316. X        FIRST!!  I would like to be the clearing house for new features
  317. X        added to XLISP.  If you want to add features for your own
  318. X        personal use, go ahead.  But, if you want to distribute your
  319. X        enhanced version, contact me first.  Please remember that the
  320. X        goal of XLISP is to provide a language to learn and experiment
  321. X        with LISP and object-oriented programming on small computers.  I
  322. X        don't want it to get so big that it requires megabytes of memory
  323. X        to run.
  324. X
  325. X
  326. X
  327. X
  328. X
  329. X
  330. X
  331. X
  332. X
  333. X
  334. X
  335. X
  336. X
  337. X
  338. X
  339. X
  340. X
  341. X
  342. X
  343. X
  344. X
  345. X
  346. X
  347. X
  348. X
  349. X
  350. X
  351. X
  352. X
  353. X
  354. X
  355. X
  356. X
  357. X
  358. X
  359. X        XLISP                 XLISP COMMAND LOOP                  Page 6
  360. X
  361. X
  362. X        XLISP COMMAND LOOP
  363. X
  364. X        When XLISP is started, it first tries to load the workspace
  365. X        "xlisp.wks" from the current directory.  If that file doesn't
  366. X        exist, XLISP builds an initial workspace, empty except for the
  367. X        built-in functions and symbols.
  368. X
  369. X        Then XLISP attempts to load "init.lsp" from the current
  370. X        directory.  It then loads any files named as parameters on the
  371. X        command line (after appending ".lsp" to their names).
  372. X
  373. X        XLISP then issues the following prompt:
  374. X
  375. X        >
  376. X
  377. X        This indicates that XLISP is waiting for an expression to be
  378. X        typed.
  379. X
  380. X        When a complete expression has been entered, XLISP attempts to
  381. X        evaluate that expression.  If the expression evaluates
  382. X        successfully, XLISP prints the result and then returns to the
  383. X        initial prompt waiting for another expression to be typed.
  384. X
  385. X
  386. X
  387. X
  388. X
  389. X
  390. X
  391. X
  392. X
  393. X
  394. X
  395. X
  396. X
  397. X
  398. X
  399. X
  400. X
  401. X
  402. X
  403. X
  404. X
  405. X
  406. X
  407. X
  408. X
  409. X
  410. X
  411. X
  412. X
  413. X
  414. X
  415. X
  416. X
  417. X
  418. X
  419. X
  420. X
  421. X
  422. X
  423. X
  424. X
  425. X        XLISP                 BREAK COMMAND LOOP                  Page 7
  426. X
  427. X
  428. X        BREAK COMMAND LOOP
  429. X
  430. X        When XLISP encounters an error while evaluating an expression,
  431. X        it attempts to handle the error in the following way:
  432. X
  433. X        If the symbol '*breakenable*' is true, the message corresponding
  434. X        to the error is printed.  If the error is correctable, the
  435. X        correction message is printed.
  436. X
  437. X        If the symbol '*tracenable*' is true, a trace back is printed.
  438. X        The number of entries printed depends on the value of the symbol
  439. X        '*tracelimit*'.  If this symbol is set to something other than a
  440. X        number, the entire trace back stack is printed.
  441. X
  442. X        XLISP then enters a read/eval/print loop to allow the user to
  443. X        examine the state of the interpreter in the context of the
  444. X        error.  This loop differs from the normal top-level
  445. X        read/eval/print loop in that if the user invokes the function
  446. X        'continue', XLISP will continue from a correctable error.  If
  447. X        the user invokes the function 'clean-up', XLISP will abort the
  448. X        break loop and return to the top level or the next lower
  449. X        numbered break loop.  When in a break loop, XLISP prefixes the
  450. X        break level to the normal prompt.
  451. X
  452. X        If the symbol '*breakenable*' is nil, XLISP looks for a
  453. X        surrounding errset function.  If one is found, XLISP examines
  454. X        the value of the print flag.  If this flag is true, the error
  455. X        message is printed.  In any case, XLISP causes the errset
  456. X        function call to return nil.
  457. X
  458. X        If there is no surrounding errset function, XLISP prints the
  459. X        error message and returns to the top level.
  460. X
  461. X
  462. X
  463. X
  464. X
  465. X
  466. X
  467. X
  468. X
  469. X
  470. X
  471. X
  472. X
  473. X
  474. X
  475. X
  476. X
  477. X
  478. X
  479. X
  480. X
  481. X
  482. X
  483. X
  484. X
  485. X
  486. X
  487. X
  488. X
  489. X
  490. X
  491. X        XLISP                      DATA TYPES                     Page 8
  492. X
  493. X
  494. X        DATA TYPES
  495. X
  496. X        There are several different data types available to XLISP
  497. X        programmers.
  498. X
  499. X            o lists
  500. X            o symbols
  501. X            o strings
  502. X            o integers
  503. X            o characters
  504. X            o floats
  505. X            o objects
  506. X            o arrays
  507. X            o streams
  508. X            o subrs (built-in functions)
  509. X            o fsubrs (special forms)
  510. X            o closures (user defined functions)
  511. X
  512. X
  513. X
  514. X
  515. X
  516. X
  517. X
  518. X
  519. X
  520. X
  521. X
  522. X
  523. X
  524. X
  525. X
  526. X
  527. X
  528. X
  529. X
  530. X
  531. X
  532. X
  533. X
  534. X
  535. X
  536. X
  537. X
  538. X
  539. X
  540. X
  541. X
  542. X
  543. X
  544. X
  545. X
  546. X
  547. X
  548. X
  549. X
  550. X
  551. X
  552. X
  553. X
  554. X
  555. X
  556. X
  557. X        XLISP                    THE EVALUATOR                    Page 9
  558. X
  559. X
  560. X        THE EVALUATOR
  561. X
  562. X        The process of evaluation in XLISP:
  563. X
  564. X        Strings, integers, characters, floats, objects, arrays, streams,
  565. X        subrs, fsubrs and closures evaluate to themselves.
  566. X
  567. X        Symbols act as variables and are evaluated by retrieving the
  568. X        value associated with their current binding.
  569. X
  570. X        Lists are evaluated by examining the first element of the list
  571. X        and then taking one of the following actions:
  572. X
  573. X            If it is a symbol, the functional binding of the symbol is
  574. X            retrieved.
  575. X
  576. X            If it is a lambda expression, a closure is constructed for
  577. X            the function described by the lambda expression.
  578. X
  579. X            If it is a subr, fsubr or closure, it stands for itself.
  580. X
  581. X            Any other value is an error.
  582. X
  583. X        Then, the value produced by the previous step is examined:
  584. X
  585. X            If it is a subr or closure, the remaining list elements are
  586. X            evaluated and the subr or closure is called with these
  587. X            evaluated expressions as arguments.
  588. X
  589. X            If it is an fsubr, the fsubr is called using the remaining
  590. X            list elements as arguments (unevaluated).
  591. X
  592. X            If it is a macro, the macro is expanded using the remaining
  593. X            list elements as arguments (unevaluated).  The macro
  594. X            expansion is then evaluated in place of the original macro
  595. X            call.
  596. X
  597. X
  598. X
  599. X
  600. X
  601. X
  602. X
  603. X
  604. X
  605. X
  606. X
  607. X
  608. X
  609. X
  610. X
  611. X
  612. X
  613. X
  614. X
  615. X
  616. X
  617. X
  618. X
  619. X
  620. X
  621. X
  622. X
  623. X        XLISP                 LEXICAL CONVENTIONS                Page 10
  624. X
  625. X
  626. X        LEXICAL CONVENTIONS
  627. X
  628. X        The following conventions must be followed when entering XLISP
  629. X        programs:
  630. X
  631. X        Comments in XLISP code begin with a semi-colon character and
  632. X        continue to the end of the line.
  633. X
  634. X        Symbol names in XLISP can consist of any sequence of non-blank
  635. X        printable characters except the following:
  636. X
  637. X                ( ) ' ` , " ;
  638. X
  639. X        Uppercase and lowercase characters are not distinguished within
  640. X        symbol names.  All lowercase characters are mapped to uppercase
  641. X        on input.
  642. X
  643. X        Integer literals consist of a sequence of digits optionally
  644. X        beginning with a '+' or '-'.  The range of values an integer can
  645. X        represent is limited by the size of a C 'long' on the machine on
  646. X        which XLISP is running.
  647. X
  648. X        Floating point literals consist of a sequence of digits
  649. X        optionally beginning with a '+' or '-' and including an embedded
  650. X        decimal point.  The range of values a floating point number can
  651. X        represent is limited by the size of a C 'float' ('double' on
  652. X        machines with 32 bit addresses) on the machine on which XLISP is
  653. X        running.
  654. X
  655. X        Literal strings are sequences of characters surrounded by double
  656. X        quotes.  Within quoted strings the '\' character is used to
  657. X        allow non-printable characters to be included.  The codes
  658. X        recognized are:
  659. X
  660. X                \\        means the character '\'
  661. X                \n       means newline
  662. X                \t       means tab
  663. X                \r       means return
  664. X                \f       means form feed
  665. X                \nnn     means the character whose octal code is nnn
  666. X
  667. X
  668. X
  669. X
  670. X
  671. X
  672. X
  673. X
  674. X
  675. X
  676. X
  677. X
  678. X
  679. X
  680. X
  681. X
  682. X
  683. X
  684. X
  685. X
  686. X
  687. X
  688. X
  689. X        XLISP                      READTABLES                    Page 11
  690. X
  691. X
  692. X        READTABLES
  693. X
  694. X        The behaviour of the reader is controlled by a data structure
  695. X        called a "readtable".  The reader uses the symbol *READTABLE* to
  696. X        locate the current readtable.  This table controls the
  697. X        interpretation of input characters.  It is an array with 128
  698. X        entries, one for each of the ASCII character codes.  Each entry
  699. X        contains one of the following things:
  700. X
  701. X                NIL             Indicating an invalid character
  702. X                :CONSTITUENT    Indicating a symbol constituent
  703. X                :WHITE-SPACE    Indicating a whitespace character
  704. X                (:TMACRO . fun) Terminating readmacro
  705. X                (:NMACRO . fun) Non-terminating readmacro
  706. X                :SESCAPE        Single escape character ('\')
  707. X                :MESCAPE        Multiple escape character ('|')
  708. X
  709. X        In the case of :TMACRO and :NMACRO, the "fun" component is a
  710. X        function.  This can either be a built-in readmacro function or a
  711. X        lambda expression.  The function should take two parameters.
  712. X        The first is the input stream and the second is the character
  713. X        that caused the invocation of the readmacro.  The readmacro
  714. X        function should return NIL to indicate that the character should
  715. X        be treated as white space or a value consed with NIL to indicate
  716. X        that the readmacro should be treated as an occurance of the
  717. X        specified value.  Of course, the readmacro code is free to read
  718. X        additional characters from the input stream.
  719. X
  720. X        XLISP defines several useful read macros:
  721. X
  722. X                '<expr>         == (quote <expr>)
  723. X                #'<expr>        == (function <expr>)
  724. X                #(<expr>...)    == an array of the specified expressions
  725. X                #x<hdigits>     == a hexadecimal number (0-9,A-F)
  726. X                #o<odigits>     == an octal number (0-7)
  727. X                #b<bdigits>     == a binary number (0-1)
  728. X                #\<char> == the ASCII code of the character
  729. X                #| ... |#       == a comment
  730. X                #:<symbol>      == an uninterned symbol
  731. X                `<expr>         == (backquote <expr>)
  732. X                ,<expr>         == (comma <expr>)
  733. X                ,@<expr>        == (comma-at <expr>)
  734. X
  735. X
  736. X
  737. X
  738. X
  739. X
  740. X
  741. X
  742. X
  743. X
  744. X
  745. X
  746. X
  747. X
  748. X
  749. X
  750. X
  751. X
  752. X
  753. X
  754. X
  755. X        XLISP                     LAMBDA LISTS                   Page 12
  756. X
  757. X
  758. X        LAMBDA LISTS
  759. X
  760. X        There are several forms in XLISP that require that a "lambda
  761. X        list" be specified.  A lambda list is a definition of the
  762. X        arguments accepted by a function.  There are four different
  763. X        types of arguments.
  764. X
  765. X        The lambda list starts with required arguments.  Required
  766. X        arguments must be specified in every call to the function.
  767. X
  768. X        The required arguments are followed by the &optional arguments.
  769. X        Optional arguments may be provided or omitted in a call.  An
  770. X        initialization expression may be specified to provide a default
  771. X        value for an &optional argument if it is omitted from a call.
  772. X        If no initialization expression is specified, an omitted
  773. X        argument is initialized to NIL.  It is also possible to provide
  774. X        the name of a 'supplied-p' variable that can be used to
  775. X        determine if a call provided a value for the argument or if the
  776. X        initialization expression was used.  If specified, the supplied-
  777. X        p variable will be bound to T if a value was specified in the
  778. X        call and NIL if the default value was used.
  779. X
  780. X        The &optional arguments are followed by the &rest argument.  The
  781. X        &rest argument gets bound to the remainder of the argument list
  782. X        after the required and &optional arguments have been removed.
  783. X
  784. X        The &rest argument is followed by the &key arguments.  When a
  785. X        keyword argument is passed to a function, a pair of values
  786. X        appears in the argument list.  The first expression in the pair
  787. X        should evaluate to a keyword symbol (a symbol that begins with a
  788. X        ':').  The value of the second expression is the value of the
  789. X        keyword argument.  Like &optional arguments, &key arguments can
  790. X        have initialization expressions and supplied-p variables.  In
  791. X        addition, it is possible to specify the keyword to be used in a
  792. X        function call.  If no keyword is specified, the keyword obtained
  793. X        by adding a ':' to the beginning of the keyword argument symbol
  794. X        is used.  In other words, if the keyword argument symbol is
  795. X        'foo', the keyword will be ':foo'.
  796. X
  797. X        The &key arguments are followed by the &aux variables.  These
  798. X        are local variables that are bound during the evaluation of the
  799. X        function body.  It is possible to have initialization
  800. X        expressions for the &aux variables.
  801. X
  802. X
  803. X
  804. X
  805. X
  806. X
  807. X
  808. X
  809. X
  810. X
  811. X
  812. X
  813. X
  814. X
  815. X
  816. X
  817. X
  818. X
  819. X
  820. X
  821. X        XLISP                     LAMBDA LISTS                   Page 13
  822. X
  823. X
  824. X        Here is the complete syntax for lambda lists:
  825. X
  826. X                (<rarg>...
  827. X                 [&optional [<oarg> | (<oarg> [<init> [<svar>]])]...]
  828. X                 [&rest <rarg>]
  829. X                 [&key
  830. X                   [<karg> | ([<karg> | (<key> <karg>)] [<init> [<svar>]])]...
  831. X                   &allow-other-keys]
  832. X                 [&aux
  833. X                   [<aux> | (<aux> [<init>])]...])
  834. X
  835. X            where:
  836. X
  837. X                <rarg>  is a required argument symbol
  838. X                <oarg>  is an &optional argument symbol
  839. X                <rarg>  is the &rest argument symbol
  840. X                <karg>  is a &key argument symbol
  841. X                <key>   is a keyword symbol
  842. X                <aux>   is an auxiliary variable symbol
  843. X                <init>  is an initialization expression
  844. X                <svar>  is a supplied-p variable symbol
  845. X
  846. X
  847. X
  848. X
  849. X
  850. X
  851. X
  852. X
  853. X
  854. X
  855. X
  856. X
  857. X
  858. X
  859. X
  860. X
  861. X
  862. X
  863. X
  864. X
  865. X
  866. X
  867. X
  868. X
  869. X
  870. X
  871. X
  872. X
  873. X
  874. X
  875. X
  876. X
  877. X
  878. X
  879. X
  880. X
  881. X
  882. X
  883. X
  884. X
  885. X
  886. X
  887. X        XLISP                       OBJECTS                      Page 14
  888. X
  889. X
  890. X        OBJECTS
  891. X
  892. X        Definitions:
  893. X
  894. X            o selector - a symbol used to select an appropriate method
  895. X            o message - a selector and a list of actual arguments
  896. X            o method - the code that implements a message
  897. X
  898. X        Since XLISP was created to provide a simple basis for
  899. X        experimenting with object-oriented programming, one of the
  900. X        primitive data types included is 'object'.  In XLISP, an object
  901. X        consists of a data structure containing a pointer to the
  902. X        object's class as well as an array containing the values of the
  903. X        object's instance variables.
  904. X
  905. X        Officially, there is no way to see inside an object (look at the
  906. X        values of its instance variables).  The only way to communicate
  907. X        with an object is by sending it a message.
  908. X
  909. X        You can send a message to an object using the 'send' function.
  910. X        This function takes the object as its first argument, the
  911. X        message selector as its second argument (which must be a symbol)
  912. X        and the message arguments as its remaining arguments.
  913. X
  914. X        The 'send' function determines the class of the receiving object
  915. X        and attempts to find a method corresponding to the message
  916. X        selector in the set of messages defined for that class.  If the
  917. X        message is not found in the object's class and the class has a
  918. X        super-class, the search continues by looking at the messages
  919. X        defined for the super-class.  This process continues from one
  920. X        super-class to the next until a method for the message is found.
  921. X        If no method is found, an error occurs.
  922. X
  923. X        A message can also be sent from the body of a method by using
  924. X        the current object, but the method lookup starts with the
  925. X        object's superclass rather than its class.  This allows a
  926. X        subclass to invoke a standard method in its parent class even
  927. X        though it overrides that method with its own specialized
  928. X        version.
  929. X
  930. X        When a method is found, the evaluator binds the receiving object
  931. X        to the symbol 'self' and evaluates the method using the
  932. X        remaining elements of the original list as arguments to the
  933. X        method.  These arguments are always evaluated prior to being
  934. X        bound to their corresponding formal arguments.  The result of
  935. X        evaluating the method becomes the result of the expression.
  936. X
  937. X
  938. X
  939. X
  940. X
  941. X
  942. X
  943. X
  944. X
  945. X
  946. X
  947. X
  948. X
  949. X
  950. X
  951. X
  952. X
  953. X        XLISP                       OBJECTS                      Page 15
  954. X
  955. X
  956. X        THE 'Object' CLASS
  957. X
  958. X        Classes:
  959. X
  960. X        Object  THE TOP OF THE CLASS HEIRARCHY
  961. X
  962. X            Messages:
  963. X
  964. X                :show  SHOW AN OBJECT'S INSTANCE VARIABLES
  965. X                    returns     the object
  966. X
  967. X                :class  RETURN THE CLASS OF AN OBJECT
  968. X                    returns     the class of the object
  969. X
  970. X                :isnew  THE DEFAULT OBJECT INITIALIZATION ROUTINE
  971. X                    returns     the object
  972. X
  973. X                :sendsuper <sel> <args>...  SEND SUPERCLASS A MESSAGE
  974. X                    <sel>       the message selector
  975. X                    <args>      the message arguments
  976. X                    returns     the result of sending the message
  977. X
  978. X
  979. X
  980. X
  981. X
  982. X
  983. X
  984. X
  985. X
  986. X
  987. X
  988. X
  989. X
  990. X
  991. X
  992. X
  993. X
  994. X
  995. X
  996. X
  997. X
  998. X
  999. X
  1000. X
  1001. X
  1002. X
  1003. X
  1004. X
  1005. X
  1006. X
  1007. X
  1008. X
  1009. X
  1010. X
  1011. X
  1012. X
  1013. X
  1014. X
  1015. X
  1016. X
  1017. X
  1018. X
  1019. X        XLISP                       OBJECTS                      Page 16
  1020. X
  1021. X
  1022. X        THE 'Class' CLASS
  1023. X
  1024. X        Class   THE CLASS OF ALL OBJECT CLASSES (including itself)
  1025. X
  1026. X            Messages:
  1027. X
  1028. X                :new  CREATE A NEW INSTANCE OF A CLASS
  1029. X                    returns     the new class object
  1030. X
  1031. X                :isnew <ivars> [<cvars> [<super>]]  INITIALIZE A NEW CLASS
  1032. X                    <ivars>     the list of instance variable symbols
  1033. X                    <cvars>     the list of class variable symbols
  1034. X                    <super>     the superclass (default is Object)
  1035. X                    returns     the new class object
  1036. X
  1037. X                :answer <msg> <fargs> <code>  ADD A MESSAGE TO A CLASS
  1038. X                    <msg>       the message symbol
  1039. X                    <fargs>     the formal argument list (lambda list)
  1040. X                    <code>      a list of executable expressions
  1041. X                    returns     the object
  1042. X
  1043. X
  1044. X        When a new instance of a class is created by sending the message
  1045. X        ':new' to an existing class, the message ':isnew' followed by
  1046. X        whatever parameters were passed to the ':new' message is sent to
  1047. X        the newly created object.
  1048. X
  1049. X        When a new class is created by sending the ':new' message to the
  1050. X        object 'Class', an optional parameter may be specified
  1051. X        indicating the superclass of the new class.  If this parameter
  1052. X        is omitted, the new class will be a subclass of 'Object'.  A
  1053. X        class inherits all instance variables, class variables, and
  1054. X        methods from its super-class.
  1055. X
  1056. X
  1057. X
  1058. X
  1059. X
  1060. X
  1061. X
  1062. X
  1063. X
  1064. X
  1065. X
  1066. X
  1067. X
  1068. X
  1069. X
  1070. X
  1071. X
  1072. X
  1073. X
  1074. X
  1075. X
  1076. X
  1077. X
  1078. X
  1079. X
  1080. X
  1081. X
  1082. X
  1083. X
  1084. X
  1085. X        XLISP                       SYMBOLS                      Page 17
  1086. X
  1087. X
  1088. X        SYMBOLS
  1089. X
  1090. X            o self - the current object (within a method context)
  1091. X            o *obarray* - the object hash table
  1092. X            o *standard-input* - the standard input stream
  1093. X            o *standard-output* - the standard output stream
  1094. X            o *error-output* - the error output stream
  1095. X            o *trace-output* - the trace output stream
  1096. X            o *debug-io* - the debug i/o stream
  1097. X            o *breakenable* - flag controlling entering break loop on errors
  1098. X            o *tracelist* - list of names of functions to trace
  1099. X            o *tracenable* - enable trace back printout on errors
  1100. X            o *tracelimit* - number of levels of trace back information
  1101. X            o *evalhook* - user substitute for the evaluator function
  1102. X            o *applyhook* - (not yet implemented)
  1103. X            o *readtable* - the current readtable
  1104. X            o *unbound* - indicator for unbound symbols
  1105. X            o *gc-flag* - controls the printing of gc messages
  1106. X            o *gc-hook* - function to call after garbage collection
  1107. X            o *integer-format* - format for printing integers ("%d" or "%ld")
  1108. X            o *float-format* - format for printing floats ("%g")
  1109. X            o *print-case* - symbol output case (:upcase or :downcase)
  1110. X
  1111. X        There are several symbols maintained by the read/eval/print
  1112. X        loop.  The symbols '+', '++', and '+++' are bound to the most
  1113. X        recent three input expressions.  The symbols '*', '**' and '***'
  1114. X        are bound to the most recent three results.  The symbol '-' is
  1115. X        bound to the expression currently being evaluated.  It becomes
  1116. X        the value of '+' at the end of the evaluation.
  1117. X
  1118. X
  1119. X
  1120. X
  1121. X
  1122. X
  1123. X
  1124. X
  1125. X
  1126. X
  1127. X
  1128. X
  1129. X
  1130. X
  1131. X
  1132. X
  1133. X
  1134. X
  1135. X
  1136. X
  1137. X
  1138. X
  1139. X
  1140. X
  1141. X
  1142. X
  1143. X
  1144. X
  1145. X
  1146. X
  1147. X
  1148. X
  1149. X
  1150. X
  1151. X        XLISP                 EVALUATION FUNCTIONS               Page 18
  1152. X
  1153. X
  1154. X        EVALUATION FUNCTIONS
  1155. X
  1156. X        (eval <expr>)  EVALUATE AN XLISP EXPRESSION
  1157. X            <expr>      the expression to be evaluated
  1158. X            returns     the result of evaluating the expression
  1159. X
  1160. X        (apply <fun> <args>)  APPLY A FUNCTION TO A LIST OF ARGUMENTS
  1161. X            <fun>       the function to apply (or function symbol)
  1162. X            <args>      the argument list
  1163. X            returns     the result of applying the function to the arguments
  1164. X
  1165. X        (funcall <fun> <arg>...)  CALL A FUNCTION WITH ARGUMENTS
  1166. X            <fun>       the function to call (or function symbol)
  1167. X            <arg>       arguments to pass to the function
  1168. X            returns     the result of calling the function with the arguments
  1169. X
  1170. X        (quote <expr>)  RETURN AN EXPRESSION UNEVALUATED
  1171. X            <expr>      the expression to be quoted (quoted)
  1172. X            returns     <expr> unevaluated
  1173. X
  1174. X        (function <expr>)  GET THE FUNCTIONAL INTERPRETATION
  1175. X            <expr>      the symbol or lambda expression (quoted)
  1176. X            returns     the functional interpretation
  1177. X
  1178. X        (backquote <expr>)  FILL IN A TEMPLATE
  1179. X            <expr>      the template
  1180. X            returns     a copy of the template with comma and comma-at
  1181. X                        expressions expanded
  1182. X
  1183. X        (lambda <args> <expr>...)  MAKE A FUNCTION CLOSURE
  1184. X            <args>      formal argument list (lambda list) (quoted)
  1185. X            <expr>      expressions of the function body
  1186. X            returns     the function closure
  1187. X
  1188. X        (get-lambda-expression <closure>)  GET THE LAMBDA EXPRESSION
  1189. X            <closure>   the closure
  1190. X            returns     the original lambda expression
  1191. X
  1192. X        (macroexpand <form>)  RECURSIVELY EXPAND MACRO CALLS
  1193. X            <form>      the form to expand
  1194. X            returns     the macro expansion
  1195. X
  1196. X        (macroexpand-1 <form>)  EXPAND A MACRO CALL
  1197. X            <form>      the macro call form
  1198. X            returns     the macro expansion
  1199. X
  1200. X
  1201. X
  1202. X
  1203. X
  1204. X
  1205. X
  1206. X
  1207. X
  1208. X
  1209. X
  1210. X
  1211. X
  1212. X
  1213. X
  1214. X
  1215. X
  1216. X
  1217. X        XLISP                   SYMBOL FUNCTIONS                 Page 19
  1218. X
  1219. X
  1220. X        SYMBOL FUNCTIONS
  1221. X
  1222. X        (set <sym> <expr>)  SET THE VALUE OF A SYMBOL
  1223. X            <sym>       the symbol being set
  1224. X            <expr>      the new value
  1225. X            returns     the new value
  1226. X
  1227. X        (setq [<sym> <expr>]...)  SET THE VALUE OF A SYMBOL
  1228. X            <sym>       the symbol being set (quoted)
  1229. X            <expr>      the new value
  1230. X            returns     the new value
  1231. X
  1232. X        (psetq [<sym> <expr>]...)  PARALLEL VERSION OF SETQ
  1233. X            <sym>       the symbol being set (quoted)
  1234. X            <expr>      the new value
  1235. X            returns     the new value
  1236. X
  1237. X        (setf [<place> <expr>]...)  SET THE VALUE OF A FIELD
  1238. X            <place>     the field specifier (quoted):
  1239. X                          <sym>                   set value of a symbol
  1240. X                          (car <expr>)            set car of a cons node
  1241. X                          (cdr <expr>)            set cdr of a cons node
  1242. X                          (nth <n> <expr>)        set nth car of a list
  1243. X                          (aref <expr> <n>)       set nth element of an array
  1244. X                          (get <sym> <prop>)      set value of a property
  1245. X                          (symbol-value <sym>)    set value of a symbol
  1246. X                          (symbol-function <sym>) set functional value of a symbol
  1247. X                          (symbol-plist <sym>)    set property list of a symbol
  1248. X            <value>     the new value
  1249. X            returns     the new value
  1250. X
  1251. X        (defun <sym> <fargs> <expr>...)  DEFINE A FUNCTION
  1252. X        (defmacro <sym> <fargs> <expr>...)  DEFINE A MACRO
  1253. X            <sym>       symbol being defined (quoted)
  1254. X            <fargs>     formal argument list (lambda list) (quoted)
  1255. X            <expr>      expressions constituting the body of the
  1256. X                        function (quoted)
  1257. X            returns     the function symbol
  1258. X
  1259. X        (gensym [<tag>])  GENERATE A SYMBOL
  1260. X            <tag>       string or number
  1261. X            returns     the new symbol
  1262. X
  1263. X        (intern <pname>)  MAKE AN INTERNED SYMBOL
  1264. X            <pname>     the symbol's print name string
  1265. X            returns     the new symbol
  1266. X
  1267. X        (make-symbol <pname>)  MAKE AN UNINTERNED SYMBOL
  1268. X            <pname>     the symbol's print name string
  1269. X            returns     the new symbol
  1270. X
  1271. X        (symbol-name <sym>)  GET THE PRINT NAME OF A SYMBOL
  1272. X            <sym>       the symbol
  1273. X            returns     the symbol's print name
  1274. X
  1275. X
  1276. X
  1277. X
  1278. X
  1279. X
  1280. X
  1281. X
  1282. X
  1283. X        XLISP                   SYMBOL FUNCTIONS                 Page 20
  1284. X
  1285. X
  1286. X        (symbol-value <sym>)  GET THE VALUE OF A SYMBOL
  1287. X            <sym>       the symbol
  1288. X            returns     the symbol's value
  1289. X
  1290. X        (symbol-function <sym>)  GET THE FUNCTIONAL VALUE OF A SYMBOL
  1291. X            <sym>       the symbol
  1292. X            returns     the symbol's functional value
  1293. X
  1294. X        (symbol-plist <sym>)  GET THE PROPERTY LIST OF A SYMBOL
  1295. X            <sym>       the symbol
  1296. X            returns     the symbol's property list
  1297. X
  1298. X        (hash <sym> <n>)  COMPUTE THE HASH INDEX FOR A SYMBOL
  1299. X            <sym>       the symbol or string
  1300. X            <n>         the table size (integer)
  1301. X            returns     the hash index (integer)
  1302. X
  1303. X
  1304. X
  1305. X
  1306. X
  1307. X
  1308. X
  1309. X
  1310. X
  1311. X
  1312. X
  1313. X
  1314. X
  1315. X
  1316. X
  1317. X
  1318. X
  1319. X
  1320. X
  1321. X
  1322. X
  1323. X
  1324. X
  1325. X
  1326. X
  1327. X
  1328. X
  1329. X
  1330. X
  1331. X
  1332. X
  1333. X
  1334. X
  1335. X
  1336. X
  1337. X
  1338. X
  1339. X
  1340. X
  1341. X
  1342. X
  1343. X
  1344. X
  1345. X
  1346. X
  1347. X
  1348. X
  1349. X        XLISP               PROPERTY LIST FUNCTIONS              Page 21
  1350. X
  1351. X
  1352. X        PROPERTY LIST FUNCTIONS
  1353. X
  1354. X        (get <sym> <prop>)  GET THE VALUE OF A PROPERTY
  1355. X            <sym>       the symbol
  1356. X            <prop>      the property symbol
  1357. X            returns     the property value or nil
  1358. X
  1359. X        (putprop <sym> <val> <prop>)  PUT A PROPERTY ONTO A PROPERTY LIST
  1360. X            <sym>       the symbol
  1361. X            <val>       the property value
  1362. X            <prop>      the property symbol
  1363. X            returns     the property value
  1364. X
  1365. X        (remprop <sym> <prop>)  REMOVE A PROPERTY
  1366. X            <sym>       the symbol
  1367. X            <prop>      the property symbol
  1368. X            returns     nil
  1369. X
  1370. X
  1371. X
  1372. X
  1373. X
  1374. X
  1375. X
  1376. X
  1377. X
  1378. X
  1379. X
  1380. X
  1381. X
  1382. X
  1383. X
  1384. X
  1385. X
  1386. X
  1387. X
  1388. X
  1389. X
  1390. X
  1391. X
  1392. X
  1393. X
  1394. X
  1395. X
  1396. X
  1397. X
  1398. X
  1399. X
  1400. X
  1401. X
  1402. X
  1403. X
  1404. X
  1405. X
  1406. X
  1407. X
  1408. X
  1409. X
  1410. X
  1411. X
  1412. X
  1413. X
  1414. X
  1415. X        XLISP                   ARRAY FUNCTIONS                  Page 22
  1416. X
  1417. X
  1418. X        ARRAY FUNCTIONS
  1419. X
  1420. X        (aref <array> <n>)  GET THE NTH ELEMENT OF AN ARRAY
  1421. X            <array>     the array
  1422. X            <n>         the array index (integer)
  1423. X            returns     the value of the array element
  1424. X
  1425. X        (make-array <size>)  MAKE A NEW ARRAY
  1426. X            <size>      the size of the new array (integer)
  1427. X            returns     the new array
  1428. X
  1429. X        (vector <expr>...)  MAKE AN INITIALIZED VECTOR
  1430. X            <expr>      the vector elements
  1431. X            returns     the new vector
  1432. X
  1433. X
  1434. X
  1435. X
  1436. X
  1437. X
  1438. X
  1439. X
  1440. X
  1441. X
  1442. X
  1443. X
  1444. X
  1445. X
  1446. X
  1447. X
  1448. X
  1449. X
  1450. X
  1451. X
  1452. X
  1453. X
  1454. X
  1455. X
  1456. X
  1457. X
  1458. X
  1459. X
  1460. X
  1461. X
  1462. X
  1463. X
  1464. X
  1465. X
  1466. X
  1467. X
  1468. X
  1469. X
  1470. X
  1471. X
  1472. X
  1473. X
  1474. X
  1475. X
  1476. X
  1477. X
  1478. X
  1479. X
  1480. X
  1481. X        XLISP                    LIST FUNCTIONS                  Page 23
  1482. X
  1483. X
  1484. X        LIST FUNCTIONS
  1485. X
  1486. X        (car <expr>)  RETURN THE CAR OF A LIST NODE
  1487. X            <expr>      the list node
  1488. X            returns     the car of the list node
  1489. X
  1490. X        (cdr <expr>)  RETURN THE CDR OF A LIST NODE
  1491. X            <expr>      the list node
  1492. X            returns     the cdr of the list node
  1493. X
  1494. X        (cxxr <expr>)  ALL CxxR COMBINATIONS
  1495. X        (cxxxr <expr>)  ALL CxxxR COMBINATIONS
  1496. X        (cxxxxr <expr>)  ALL CxxxxR COMBINATIONS
  1497. X
  1498. X        (first <expr>)   A SYNONYM FOR CAR
  1499. X        (second <expr>)  A SYNONYM FOR CADR
  1500. X        (third <expr>)   A SYNONYM FOR CADDR
  1501. X        (fourth <expr>)  A SYNONYM FOR CADDDR
  1502. X        (rest <expr>)    A SYNONYM FOR CDR
  1503. X
  1504. X        (cons <expr1> <expr2>)  CONSTRUCT A NEW LIST NODE
  1505. X            <expr1>     the car of the new list node
  1506. X            <expr2>     the cdr of the new list node
  1507. X            returns     the new list node
  1508. X
  1509. X        (list <expr>...)  CREATE A LIST OF VALUES
  1510. X            <expr>      expressions to be combined into a list
  1511. X            returns     the new list
  1512. X
  1513. X        (append <expr>...)  APPEND LISTS
  1514. X            <expr>      lists whose elements are to be appended
  1515. X            returns     the new list
  1516. X
  1517. X        (reverse <expr>)  REVERSE A LIST
  1518. X            <expr>      the list to reverse
  1519. X            returns     a new list in the reverse order
  1520. X
  1521. X        (last <list>)  RETURN THE LAST LIST NODE OF A LIST
  1522. X            <list>      the list
  1523. X            returns     the last list node in the list
  1524. X
  1525. X        (member <expr> <list> &key :test :test-not)  FIND AN EXPRESSION IN A LIST
  1526. X            <expr>      the expression to find
  1527. X            <list>      the list to search
  1528. X            :test       the test function (defaults to eql)
  1529. X            :test-not   the test function (sense inverted)      
  1530. X            returns     the remainder of the list starting with the expression
  1531. X
  1532. X        (assoc <expr> <alist> &key :test :test-not)  FIND AN EXPRESSION IN AN A-LIST
  1533. X            <expr>      the expression to find
  1534. X            <alist>     the association list
  1535. X            :test       the test function (defaults to eql)
  1536. X            :test-not   the test function (sense inverted)      
  1537. X            returns     the alist entry or nil
  1538. X
  1539. X
  1540. X
  1541. X
  1542. X
  1543. X
  1544. X
  1545. X
  1546. X
  1547. X        XLISP                    LIST FUNCTIONS                  Page 24
  1548. X
  1549. X
  1550. X        (remove <expr> <list> &key :test :test-not)  REMOVE ELEMENTS FROM A LIST
  1551. X            <expr>      the element to remove
  1552. X            <list>      the list
  1553. X            :test       the test function (defaults to eql)
  1554. X            :test-not   the test function (sense inverted)      
  1555. X            returns     copy of list with matching expressions removed
  1556. X
  1557. X        (remove-if <test> <list>)  REMOVE ELEMENTS THAT PASS TEST
  1558. X            <test>      the test predicate
  1559. X            <list>      the list
  1560. X            returns     copy of list with matching elements removed
  1561. X
  1562. X        (remove-if-not <test> <list>)  REMOVE ELEMENTS THAT FAIL TEST
  1563. X            <test>      the test predicate
  1564. X            <list>      the list
  1565. X            returns     copy of list with non-matching elements removed
  1566. X
  1567. X        (length <expr>)  FIND THE LENGTH OF A LIST, VECTOR OR STRING
  1568. X            <expr>      the list, vector or string
  1569. X            returns     the length of the list, vector or string
  1570. X
  1571. X        (nth <n> <list>)  RETURN THE NTH ELEMENT OF A LIST
  1572. X            <n>         the number of the element to return (zero origin)
  1573. X            <list>      the list
  1574. X            returns     the nth element or nil if the list isn't that long
  1575. X
  1576. X        (nthcdr <n> <list>)  RETURN THE NTH CDR OF A LIST
  1577. X            <n>         the number of the element to return (zero origin)
  1578. X            <list>      the list
  1579. X            returns     the nth cdr or nil if the list isn't that long
  1580. X
  1581. X        (mapc <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CARS
  1582. X            <fcn>       the function or function name
  1583. X            <listn>     a list for each argument of the function
  1584. X            returns     the first list of arguments
  1585. X
  1586. X        (mapcar <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CARS
  1587. X            <fcn>       the function or function name
  1588. X            <listn>     a list for each argument of the function
  1589. X            returns     a list of the values returned
  1590. X
  1591. X        (mapl <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CDRS
  1592. X            <fcn>       the function or function name
  1593. X            <listn>     a list for each argument of the function
  1594. X            returns     the first list of arguments
  1595. X
  1596. X        (maplist <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CDRS
  1597. X            <fcn>       the function or function name
  1598. X            <listn>     a list for each argument of the function
  1599. X            returns     a list of the values returned
  1600. X
  1601. X
  1602. X
  1603. X
  1604. X
  1605. X
  1606. X
  1607. X
  1608. X
  1609. X
  1610. X
  1611. X
  1612. X
  1613. X        XLISP                    LIST FUNCTIONS                  Page 25
  1614. X
  1615. X
  1616. X        (subst <to> <from> <expr> &key :test :test-not)  SUBSTITUTE EXPRESSIONS
  1617. X            <to>        the new expression
  1618. X            <from>      the old expression
  1619. X            <expr>      the expression in which to do the substitutions
  1620. X            :test       the test function (defaults to eql)
  1621. X            :test-not   the test function (sense inverted)      
  1622. X            returns     the expression with substitutions
  1623. X
  1624. X        (sublis <alist> <expr> &key :test :test-not)  SUBSTITUTE WITH AN A-LIST
  1625. X            <alist>     the association list
  1626. X            <expr>      the expression in which to do the substitutions
  1627. X            :test       the test function (defaults to eql)
  1628. X            :test-not   the test function (sense inverted)      
  1629. X            returns     the expression with substitutions
  1630. X
  1631. X
  1632. X
  1633. X
  1634. X
  1635. X
  1636. X
  1637. X
  1638. X        XLISP              DESTRUCTIVE LIST FUNCTIONS            Page 26
  1639. X
  1640. X
  1641. X        DESTRUCTIVE LIST FUNCTIONS
  1642. X
  1643. X        (rplaca <list> <expr>)  REPLACE THE CAR OF A LIST NODE
  1644. X            <list>      the list node
  1645. X            <expr>      the new value for the car of the list node
  1646. X            returns     the list node after updating the car
  1647. X
  1648. X        (rplacd <list> <expr>)  REPLACE THE CDR OF A LIST NODE
  1649. X            <list>      the list node
  1650. X            <expr>      the new value for the cdr of the list node
  1651. X            returns     the list node after updating the cdr
  1652. X
  1653. X        (nconc <list>...)  DESTRUCTIVELY CONCATENATE LISTS
  1654. X            <list>      lists to concatenate
  1655. X            returns     the result of concatenating the lists
  1656. X
  1657. X        (delete <expr> &key :test :test-not)  DELETE ELEMENTS FROM A LIST
  1658. X            <expr>      the element to delete
  1659. X            <list>      the list
  1660. X            :test       the test function (defaults to eql)
  1661. X            :test-not   the test function (sense inverted)      
  1662. X            returns     the list with the matching expressions deleted
  1663. X
  1664. X        (delete-if <test> <list>)  DELETE ELEMENTS THAT PASS TEST
  1665. X            <test>      the test predicate
  1666. X            <list>      the list
  1667. X            returns     the list with matching elements deleted
  1668. X
  1669. X        (delete-if-not <test> <list>)  DELETE ELEMENTS THAT FAIL TEST
  1670. X            <test>      the test predicate
  1671. X            <list>      the list
  1672. X            returns     the list with non-matching elements deleted
  1673. X
  1674. X        (sort <list> <test>)  SORT A LIST
  1675. X            <list>      the list to sort
  1676. X            <test>      the comparison function
  1677. X            returns     the sorted list
  1678. X
  1679. X
  1680. X
  1681. X
  1682. X
  1683. X
  1684. X
  1685. X
  1686. X
  1687. X
  1688. X
  1689. X
  1690. X
  1691. X
  1692. X
  1693. X
  1694. X
  1695. X
  1696. X
  1697. X
  1698. X
  1699. X
  1700. X
  1701. X
  1702. X
  1703. X
  1704. X        XLISP                 PREDICATE FUNCTIONS                Page 27
  1705. X
  1706. X
  1707. X        PREDICATE FUNCTIONS
  1708. X
  1709. X        (atom <expr>)  IS THIS AN ATOM?
  1710. X            <expr>      the expression to check
  1711. X            returns     t if the value is an atom, nil otherwise
  1712. X
  1713. X        (symbolp <expr>)  IS THIS A SYMBOL?
  1714. X            <expr>      the expression to check
  1715. X            returns     t if the expression is a symbol, nil otherwise
  1716. X
  1717. X        (numberp <expr>)  IS THIS A NUMBER?
  1718. X            <expr>      the expression to check
  1719. X            returns     t if the expression is a number, nil otherwise
  1720. X
  1721. X        (null <expr>)  IS THIS AN EMPTY LIST?
  1722. X            <expr>      the list to check
  1723. X            returns     t if the list is empty, nil otherwise
  1724. X
  1725. X        (not <expr>)  IS THIS FALSE?
  1726. X            <expr>      the expression to check
  1727. X            return      t if the value is nil, nil otherwise
  1728. X
  1729. X        (listp <expr>)  IS THIS A LIST?
  1730. X            <expr>      the expression to check
  1731. X            returns     t if the value is a cons or nil, nil otherwise
  1732. X
  1733. X        (endp <list>)  IS THIS THE END OF A LIST
  1734. X            <list>      the list
  1735. X            returns     t if the value is nil, nil otherwise
  1736. X
  1737. X        (consp <expr>)  IS THIS A NON-EMPTY LIST?
  1738. X            <expr>      the expression to check
  1739. X            returns     t if the value is a cons, nil otherwise
  1740. X
  1741. X        (integerp <expr>)  IS THIS AN INTEGER?
  1742. X            <expr>      the expression to check
  1743. X            returns     t if the value is an integer, nil otherwise
  1744. X
  1745. X        (floatp <expr>)  IS THIS A FLOAT?
  1746. X            <expr>      the expression to check
  1747. X            returns     t if the value is a float, nil otherwise
  1748. X
  1749. X        (stringp <expr>)  IS THIS A STRING?
  1750. X            <expr>      the expression to check
  1751. X            returns     t if the value is a string, nil otherwise
  1752. X
  1753. X        (characterp <expr>)  IS THIS A CHARACTER?
  1754. X            <expr>      the expression to check
  1755. X            returns     t if the value is a character, nil otherwise
  1756. X
  1757. X        (arrayp <expr>)  IS THIS AN ARRAY?
  1758. X            <expr>      the expression to check
  1759. X            returns     t if the value is an array, nil otherwise
  1760. X
  1761. X
  1762. X
  1763. X
  1764. X
  1765. X
  1766. X
  1767. X
  1768. X
  1769. X
  1770. X        XLISP                 PREDICATE FUNCTIONS                Page 28
  1771. X
  1772. X
  1773. X        (streamp <expr>)  IS THIS A STREAM?
  1774. X            <expr>      the expression to check
  1775. X            returns     t if the value is a stream, nil otherwise
  1776. X
  1777. X        (objectp <expr>)  IS THIS AN OBJECT?
  1778. X            <expr>      the expression to check
  1779. X            returns     t if the value is an object, nil otherwise
  1780. X
  1781. X        (boundp <sym>)  IS A VALUE BOUND TO THIS SYMBOL?
  1782. X            <sym>       the symbol
  1783. X            returns     t if a value is bound to the symbol, nil otherwise
  1784. X
  1785. X        (fboundp <sym>)  IS A FUNCTIONAL VALUE BOUND TO THIS SYMBOL?
  1786. X            <sym>       the symbol
  1787. X            returns     t if a functional value is bound to the symbol,
  1788. X                        nil otherwise
  1789. X
  1790. X        (minusp <expr>)  IS THIS NUMBER NEGATIVE?
  1791. X            <expr>      the number to test
  1792. X            returns     t if the number is negative, nil otherwise
  1793. X
  1794. X        (zerop <expr>)  IS THIS NUMBER ZERO?
  1795. X            <expr>      the number to test
  1796. X            returns     t if the number is zero, nil otherwise
  1797. X
  1798. X        (plusp <expr>)  IS THIS NUMBER POSITIVE?
  1799. X            <expr>      the number to test
  1800. X            returns     t if the number is positive, nil otherwise
  1801. X
  1802. X        (evenp <expr>)  IS THIS INTEGER EVEN?
  1803. X            <expr>      the integer to test
  1804. X            returns     t if the integer is even, nil otherwise
  1805. X
  1806. X        (oddp <expr>)  IS THIS INTEGER ODD?
  1807. X            <expr>      the integer to test
  1808. X            returns     t if the integer is odd, nil otherwise
  1809. X
  1810. X        (eq <expr1> <expr2>)  ARE THE EXPRESSIONS IDENTICAL?
  1811. X            <expr1>     the first expression
  1812. X            <expr2>     the second expression
  1813. X            returns     t if they are equal, nil otherwise
  1814. X
  1815. X        (eql <expr1> <expr2>)  ARE THE EXPRESSIONS IDENTICAL?
  1816. X                                (WORKS WITH ALL NUMBERS)
  1817. X            <expr1>     the first expression
  1818. X            <expr2>     the second expression
  1819. X            returns     t if they are equal, nil otherwise
  1820. X
  1821. X        (equal <expr1> <expr2>)  ARE THE EXPRESSIONS EQUAL?
  1822. X            <expr1>     the first expression
  1823. X            <expr2>     the second expression
  1824. X            returns     t if they are equal, nil otherwise
  1825. X
  1826. X
  1827. X
  1828. X
  1829. X
  1830. X
  1831. X
  1832. X
  1833. X
  1834. X
  1835. X
  1836. X        XLISP                  CONTROL CONSTRUCTS                Page 29
  1837. X
  1838. X
  1839. X        CONTROL CONSTRUCTS
  1840. X
  1841. X        (cond <pair>...)  EVALUATE CONDITIONALLY
  1842. X            <pair>      pair consisting of:
  1843. X                            (<pred> <expr>...)
  1844. X                          where
  1845. X                            <pred>      is a predicate expression
  1846. X                            <expr>      evaluated if the predicate
  1847. X                                        is not nil
  1848. X            returns     the value of the first expression whose predicate
  1849. X                        is not nil
  1850. X
  1851. X        (and <expr>...)  THE LOGICAL AND OF A LIST OF EXPRESSIONS
  1852. X            <expr>      the expressions to be ANDed
  1853. X            returns     nil if any expression evaluates to nil,
  1854. X                        otherwise the value of the last expression
  1855. X                        (evaluation of expressions stops after the first
  1856. X                         expression that evaluates to nil)
  1857. X
  1858. X        (or <expr>...)  THE LOGICAL OR OF A LIST OF EXPRESSIONS
  1859. X            <expr>      the expressions to be ORed
  1860. X            returns     nil if all expressions evaluate to nil,
  1861. X                        otherwise the value of the first non-nil expression
  1862. X                        (evaluation of expressions stops after the first
  1863. X                         expression that does not evaluate to nil)
  1864. X
  1865. X        (if <texpr> <expr1> [<expr2>])  EVALUATE EXPRESSIONS CONDITIONALLY
  1866. X            <texpr>     the test expression
  1867. X            <expr1>     the expression to be evaluated if texpr is non-nil
  1868. X            <expr2>     the expression to be evaluated if texpr is nil
  1869. X            returns     the value of the selected expression
  1870. X
  1871. X        (when <texpr> <expr>...)  EVALUATE ONLY WHEN A CONDITION IS TRUE
  1872. X            <texpr>     the test expression
  1873. X            <expr>      the expression(s) to be evaluted if texpr is non-nil
  1874. X            returns     the value of the last expression or nil
  1875. X
  1876. X        (unless <texpr> <expr>...)  EVALUATE ONLY WHEN A CONDITION IS FALSE
  1877. X            <texpr>     the test expression
  1878. X            <expr>      the expression(s) to be evaluated if texpr is nil
  1879. X            returns     the value of the last expression or nil
  1880. X
  1881. X          (case <expr> <case>...)  SELECT BY CASE
  1882. X            <expr>      the selection expression
  1883. X            <case>      pair consisting of:
  1884. X                            (<value> <expr>...)
  1885. X                          where:
  1886. X                            <value>     is a single expression or a list of
  1887. X                                        expressions (unevaluated)
  1888. X                            <expr>      are expressions to execute if the
  1889. X                                        case matches
  1890. X            returns     the value of the last expression of the matching case
  1891. X
  1892. X
  1893. X
  1894. X
  1895. X
  1896. X
  1897. X
  1898. X
  1899. X
  1900. X
  1901. X
  1902. X        XLISP                  CONTROL CONSTRUCTS                Page 30
  1903. X
  1904. X
  1905. X        (let (<binding>...) <expr>...)  CREATE LOCAL BINDINGS
  1906. X        (let* (<binding>...) <expr>...)  LET WITH SEQUENTIAL BINDING
  1907. X            <binding>   the variable bindings each of which is either:
  1908. X                        1)  a symbol (which is initialized to nil)
  1909. X                        2)  a list whose car is a symbol and whose cadr
  1910. X                                is an initialization expression
  1911. X            <expr>      the expressions to be evaluated
  1912. X            returns     the value of the last expression
  1913. X
  1914. X        (flet (<binding>...) <expr>...)  CREATE LOCAL FUNCTIONS
  1915. X        (labels (<binding>...) <expr>...)  FLET WITH RECURSIVE FUNCTIONS
  1916. X        (macrolet (<binding>...) <expr>...)  CREATE LOCAL MACROS
  1917. X            <binding>   the function bindings each of which is:
  1918. X                          (<sym> <fargs> <expr>...)
  1919. X                        where:
  1920. X                            <sym>       the function/macro name
  1921. X                            <fargs>     formal argument list (lambda list)
  1922. X                            <expr>      expressions constituting the body of
  1923. X                                        the function/macro
  1924. X            <expr>      the expressions to be evaluated
  1925. X            returns     the value of the last expression
  1926. X
  1927. X        (catch <sym> <expr>...)  EVALUATE EXPRESSIONS AND CATCH THROWS
  1928. X            <sym>       the catch tag
  1929. X            <expr>      expressions to evaluate
  1930. X            returns     the value of the last expression the throw expression
  1931. X
  1932. X        (throw <sym> [<expr>])  THROW TO A CATCH
  1933. X            <sym>       the catch tag
  1934. X            <expr>      the value for the catch to return (defaults to nil)
  1935. X            returns     never returns
  1936. X
  1937. X        (unwind-protect <expr> <cexpr>...)  PROTECT EVALUATION OF AN EXPRESSION
  1938. X            <expr>      the expression to protect
  1939. X            <cexpr>     the cleanup expressions
  1940. X            returns     the value of the expression
  1941. X          Note:  unwind-protect guarantees to execute the cleanup expressions
  1942. X                 even if a non-local exit terminates the evaluation of the
  1943. X                 protected expression
  1944. X
  1945. X
  1946. X
  1947. X
  1948. X
  1949. X
  1950. X
  1951. X
  1952. X
  1953. X
  1954. X
  1955. X
  1956. X
  1957. X
  1958. X
  1959. X
  1960. X
  1961. X
  1962. X
  1963. X
  1964. X
  1965. X
  1966. X
  1967. X
  1968. X        XLISP                  LOOPING CONSTRUCTS                Page 31
  1969. X
  1970. X
  1971. X        LOOPING CONSTRUCTS
  1972. X
  1973. X        (loop <expr>...)  BASIC LOOPING FORM
  1974. X            <expr>      the body of the loop
  1975. X            returns     never returns (must use non-local exit)
  1976. X
  1977. X        (do (<binding>...) (<texpr> <rexpr>...) <expr>...)
  1978. X        (do* (<binding>...) (<texpr> <rexpr>...) <expr>...)
  1979. X            <binding>   the variable bindings each of which is either:
  1980. X                        1)  a symbol (which is initialized to nil)
  1981. X                        2)  a list of the form: (<sym> <init> [<step>])
  1982. X                            where:
  1983. X                                <sym>  is the symbol to bind
  1984. X                                <init> is the initial value of the symbol
  1985. X                                <step> is a step expression
  1986. X            <texpr>     the termination test expression
  1987. X            <rexpr>     result expressions (the default is nil)
  1988. X            <expr>      the body of the loop (treated like an implicit prog)
  1989. X            returns     the value of the last result expression
  1990. X
  1991. X        (dolist (<sym> <expr> [<rexpr>]) <expr>...)  LOOP THROUGH A LIST
  1992. X            <sym>       the symbol to bind to each list element
  1993. X            <expr>      the list expression
  1994. X            <rexpr>     the result expression (the default is nil)
  1995. X            <expr>      the body of the loop (treated like an implicit prog)
  1996. X
  1997. X        (dotimes (<sym> <expr> [<rexpr>]) <expr>...)  LOOP FROM ZERO TO N-1
  1998. X            <sym>       the symbol to bind to each value from 0 to n-1
  1999. X            <expr>      the number of times to loop
  2000. X            <rexpr>     the result expression (the default is nil)
  2001. X            <expr>      the body of the loop (treated like an implicit prog)
  2002. X
  2003. X
  2004. X
  2005. X
  2006. X
  2007. X
  2008. X
  2009. X
  2010. X
  2011. X
  2012. X
  2013. X
  2014. X
  2015. X
  2016. X
  2017. X
  2018. X
  2019. X
  2020. X
  2021. X
  2022. X
  2023. X
  2024. X
  2025. X
  2026. X
  2027. X
  2028. X
  2029. X
  2030. X
  2031. X
  2032. X
  2033. X
  2034. X        XLISP                 THE PROGRAM FEATURE                Page 32
  2035. X
  2036. X
  2037. X        THE PROGRAM FEATURE
  2038. X
  2039. X        (prog (<binding>...) <expr>...)  THE PROGRAM FEATURE
  2040. X        (prog* (<binding>...) <expr>...)  PROG WITH SEQUENTIAL BINDING
  2041. X            <binding>   the variable bindings each of which is either:
  2042. X                        1)  a symbol (which is initialized to nil)
  2043. X                        2)  a list whose car is a symbol and whose cadr
  2044. X                                is an initialization expression
  2045. X            <expr>      expressions to evaluate or tags (symbols)
  2046. X            returns     nil or the argument passed to the return function
  2047. X
  2048. X        (block <name> <expr>...)  NAMED BLOCK
  2049. X            <name>      the block name (symbol)
  2050. X            <expr>      the block body
  2051. X            returns     the value of the last expression
  2052. X
  2053. X        (return [<expr>])  CAUSE A PROG CONSTRUCT TO RETURN A VALUE
  2054. X            <expr>      the value (defaults to nil)
  2055. X            returns     never returns
  2056. X
  2057. X        (return-from <name> [<value>])  RETURN FROM A NAMED BLOCK
  2058. X            <name>      the block name (symbol)
  2059. X            <value>     the value to return (defaults to nil)
  2060. X            returns     never returns
  2061. X
  2062. X        (tagbody <expr>...)  BLOCK WITH LABELS
  2063. X            <expr>      expression(s) to evaluate or tags (symbols)
  2064. X            returns     nil
  2065. X
  2066. X        (go <sym>)  GO TO A TAG WITHIN A TAGBODY OR PROG
  2067. X            <sym>       the tag (quoted)
  2068. X            returns     never returns
  2069. X
  2070. X        (progv <slist> <vlist> <expr>...)  DYNAMICALLY BIND SYMBOLS
  2071. X            <slist>     list of symbols
  2072. X            <vlist>     list of values to bind to the symbols
  2073. X            <expr>      expression(s) to evaluate
  2074. X            returns     the value of the last expression
  2075. X
  2076. X        (prog1 <expr1> <expr>...)  EXECUTE EXPRESSIONS SEQUENTIALLY
  2077. X            <expr1>     the first expression to evaluate
  2078. X            <expr>      the remaining expressions to evaluate
  2079. X            returns     the value of the first expression
  2080. X
  2081. X        (prog2 <expr1> <expr2> <expr>...)  EXECUTE EXPRESSIONS SEQUENTIALLY
  2082. X            <expr1>     the first expression to evaluate
  2083. X            <expr2>     the second expression to evaluate
  2084. X            <expr>      the remaining expressions to evaluate
  2085. X            returns     the value of the second expression
  2086. X
  2087. X        (progn <expr>...)  EXECUTE EXPRESSIONS SEQUENTIALLY
  2088. X            <expr>      the expressions to evaluate
  2089. X            returns     the value of the last expression (or nil)
  2090. X
  2091. X
  2092. X
  2093. X
  2094. X
  2095. X
  2096. X
  2097. X
  2098. X
  2099. X
  2100. X        XLISP             DEBUGGING AND ERROR HANDLING           Page 33
  2101. X
  2102. X
  2103. X        DEBUGGING AND ERROR HANDLING
  2104. X
  2105. X        (trace <sym>)  ADD A FUNCTION TO THE TRACE LIST
  2106. X            <sym>       the function to add (quoted)
  2107. X            returns     the trace list
  2108. X
  2109. X        (untrace <sym>)  REMOVE A FUNCTION FROM THE TRACE LIST
  2110. X            <sym>       the function to remove (quoted)
  2111. X            returns     the trace list
  2112. X
  2113. X        (error <emsg> [<arg>])  SIGNAL A NON-CORRECTABLE ERROR
  2114. X            <emsg>      the error message string
  2115. X            <arg>       the argument expression (printed after the message)
  2116. X            returns     never returns
  2117. X
  2118. X        (cerror <cmsg> <emsg> [<arg>])  SIGNAL A CORRECTABLE ERROR
  2119. X            <cmsg>      the continue message string
  2120. X            <emsg>      the error message string
  2121. X            <arg>       the argument expression (printed after the message)
  2122. X            returns     nil when continued from the break loop
  2123. X
  2124. X        (break [<bmsg> [<arg>]])  ENTER A BREAK LOOP
  2125. X            <bmsg>      the break message string (defaults to "**BREAK**")
  2126. X            <arg>       the argument expression (printed after the message)
  2127. X            returns     nil when continued from the break loop
  2128. X
  2129. X        (clean-up)  CLEAN-UP AFTER AN ERROR
  2130. X            returns     never returns
  2131. X
  2132. X        (top-level)  CLEAN-UP AFTER AN ERROR AND RETURN TO THE TOP LEVEL
  2133. X            returns     never returns
  2134. X
  2135. X        (continue)  CONTINUE FROM A CORRECTABLE ERROR
  2136. X            returns     never returns
  2137. X
  2138. X        (errset <expr> [<pflag>])  TRAP ERRORS
  2139. X            <expr>      the expression to execute
  2140. X            <pflag>     flag to control printing of the error message
  2141. X            returns     the value of the last expression consed with nil
  2142. X                        or nil on error
  2143. X
  2144. X        (baktrace [<n>])  PRINT N LEVELS OF TRACE BACK INFORMATION
  2145. X            <n>         the number of levels (defaults to all levels)
  2146. X            returns     nil
  2147. X
  2148. X        (evalhook <expr> <ehook> <ahook> [<env>])  EVALUATE WITH HOOKS
  2149. X            <expr>      the expression to evaluate
  2150. X            <ehook>     the value for *evalhook*
  2151. X            <ahook>     the value for *applyhook*
  2152. X            <env>       the environment (default is nil)
  2153. X            returns     the result of evaluating the expression
  2154. X
  2155. X
  2156. X
  2157. X
  2158. X
  2159. X
  2160. X
  2161. X
  2162. X
  2163. X
  2164. X
  2165. X
  2166. X        XLISP                 ARITHMETIC FUNCTIONS               Page 34
  2167. X
  2168. X
  2169. X        ARITHMETIC FUNCTIONS
  2170. X
  2171. X        (truncate <expr>)  TRUNCATES A FLOATING POINT NUMBER TO AN INTEGER
  2172. X            <expr>      the number
  2173. X            returns     the result of truncating the number
  2174. X
  2175. X        (float <expr>)  CONVERTS AN INTEGER TO A FLOATING POINT NUMBER
  2176. X            <expr>      the number
  2177. X            returns     the result of floating the integer
  2178. X
  2179. X        (+ <expr>...)  ADD A LIST OF NUMBERS
  2180. X            <expr>      the numbers
  2181. X            returns     the result of the addition
  2182. X
  2183. X        (- <expr>...)  SUBTRACT A LIST OF NUMBERS OR NEGATE A SINGLE NUMBER
  2184. X            <expr>      the numbers
  2185. X            returns     the result of the subtraction
  2186. X
  2187. X        (* <expr>...)  MULTIPLY A LIST OF NUMBERS
  2188. X            <expr>      the numbers
  2189. X            returns     the result of the multiplication
  2190. X
  2191. X        (/ <expr>...)  DIVIDE A LIST OF NUMBERS
  2192. X            <expr>      the numbers
  2193. X            returns     the result of the division
  2194. X
  2195. X        (1+ <expr>)  ADD ONE TO A NUMBER
  2196. X            <expr>      the number
  2197. X            returns     the number plus one
  2198. X
  2199. X        (1- <expr>)  SUBTRACT ONE FROM A NUMBER
  2200. X            <expr>      the number
  2201. X            returns     the number minus one
  2202. X
  2203. X        (rem <expr>...)  REMAINDER OF A LIST OF NUMBERS
  2204. X            <expr>      the numbers
  2205. X            returns     the result of the remainder operation
  2206. X
  2207. X        (min <expr>...)  THE SMALLEST OF A LIST OF NUMBERS
  2208. X            <expr>      the expressions to be checked
  2209. X            returns     the smallest number in the list
  2210. X
  2211. X        (max <expr>...)  THE LARGEST OF A LIST OF NUMBERS
  2212. X            <expr>      the expressions to be checked
  2213. X            returns     the largest number in the list
  2214. X
  2215. X        (abs <expr>)  THE ABSOLUTE VALUE OF A NUMBER
  2216. X            <expr>      the number
  2217. X            returns     the absolute value of the number
  2218. X
  2219. X        (gcd <n1> <n2>...)  COMPUTE THE GREATEST COMMON DIVISOR
  2220. X            <n1>        the first number (integer)
  2221. X            <n2>        the second number(s) (integer)
  2222. X            returns     the greatest common divisor
  2223. X
  2224. X
  2225. X
  2226. X
  2227. X
  2228. X
  2229. X
  2230. X
  2231. X
  2232. X        XLISP                 ARITHMETIC FUNCTIONS               Page 35
  2233. X
  2234. X
  2235. X        (random <n>)  COMPUTE A RANDOM NUMBER BETWEEN 1 and N-1
  2236. X            <n>         the upper bound (integer)
  2237. X            returns     a random number
  2238. X
  2239. X        (sin <expr>)  COMPUTE THE SINE OF A NUMBER
  2240. X            <expr>      the floating point number
  2241. X            returns     the sine of the number
  2242. X
  2243. X        (cos <expr>)  COMPUTE THE COSINE OF A NUMBER
  2244. X            <expr>      the floating point number
  2245. X            returns     the cosine of the number
  2246. X
  2247. X        (tan <expr>)  COMPUTE THE TANGENT OF A NUMBER
  2248. X            <expr>      the floating point number
  2249. X            returns     the tangent of the number
  2250. X
  2251. X        (expt <x-expr> <y-expr>)  COMPUTE X TO THE Y POWER
  2252. X            <x-expr>    the floating point number
  2253. X            <y-expr>    the floating point exponent
  2254. X            returns     x to the y power
  2255. X
  2256. X        (exp <x-expr>)  COMPUTE E TO THE X POWER
  2257. X            <x-expr>    the floating point number
  2258. X            returns     e to the x power
  2259. X
  2260. X        (sqrt <expr>)  COMPUTE THE SQUARE ROOT OF A NUMBER
  2261. X            <expr>      the floating point number
  2262. X            returns     the square root of the number
  2263. X
  2264. X        (< <n1> <n2>...)  TEST FOR LESS THAN
  2265. X        (<= <n1> <n2>...)  TEST FOR LESS THAN OR EQUAL TO
  2266. X        (= <n1> <n2>...)  TEST FOR EQUAL TO
  2267. X        (/= <n1> <n2>...)  TEST FOR NOT EQUAL TO
  2268. X        (>= <n1> <n2>...)  TEST FOR GREATER THAN OR EQUAL TO
  2269. X        (> <n1> <n2>...)  TEST FOR GREATER THAN
  2270. X            <n1>        the first number to compare
  2271. X            <n2>        the second number to compare
  2272. X            returns     the result of comparing <n1> with <n2>...
  2273. X
  2274. X
  2275. X
  2276. X
  2277. X
  2278. X
  2279. X
  2280. X
  2281. X
  2282. X
  2283. X
  2284. X
  2285. X
  2286. X
  2287. X
  2288. X
  2289. X
  2290. X
  2291. X
  2292. X
  2293. X
  2294. X
  2295. X
  2296. X
  2297. X
  2298. X        XLISP              BITWISE LOGICAL FUNCTIONS             Page 36
  2299. X
  2300. X
  2301. X        BITWISE LOGICAL FUNCTIONS
  2302. X
  2303. X        (logand <expr>...)  THE BITWISE AND OF A LIST OF NUMBERS
  2304. X            <expr>      the numbers
  2305. X            returns     the result of the and operation
  2306. X
  2307. X        (logior <expr>...)  THE BITWISE INCLUSIVE OR OF A LIST OF NUMBERS
  2308. X            <expr>      the numbers
  2309. X            returns     the result of the inclusive or operation
  2310. X
  2311. X        (logxor <expr>...)  THE BITWISE EXCLUSIVE OR OF A LIST OF NUMBERS
  2312. X            <expr>      the numbers
  2313. X            returns     the result of the exclusive or operation
  2314. X
  2315. X        (lognot <expr>)  THE BITWISE NOT OF A NUMBER
  2316. X            <expr>      the number
  2317. X            returns     the bitwise inversion of number
  2318. X
  2319. X
  2320. X
  2321. X
  2322. X
  2323. X
  2324. X
  2325. X
  2326. X
  2327. X
  2328. X
  2329. X
  2330. X
  2331. X
  2332. X
  2333. X
  2334. X
  2335. X
  2336. X
  2337. X
  2338. X
  2339. X
  2340. X
  2341. X
  2342. X
  2343. X
  2344. X
  2345. X
  2346. X
  2347. X
  2348. X
  2349. X
  2350. X
  2351. X
  2352. X
  2353. X
  2354. X
  2355. X
  2356. X
  2357. X
  2358. X
  2359. X
  2360. X
  2361. X
  2362. X
  2363. X
  2364. X        XLISP                   STRING FUNCTIONS                 Page 37
  2365. X
  2366. X
  2367. X        STRING FUNCTIONS
  2368. X
  2369. X        (string <expr>)  MAKE A STRING FROM AN INTEGER ASCII VALUE
  2370. X            <expr>      the integer
  2371. X            returns     a one character string
  2372. X
  2373. X        (string-trim <bag> <str>)  TRIM BOTH ENDS OF A STRING
  2374. X            <bag>       a string containing characters to trim
  2375. X            <str>       the string to trim
  2376. X            returns     a trimed copy of the string
  2377. X
  2378. X        (string-left-trim <bag> <str>)  TRIM THE LEFT END OF A STRING
  2379. X            <bag>       a string containing characters to trim
  2380. X            <str>       the string to trim
  2381. X            returns     a trimed copy of the string
  2382. X
  2383. X        (string-right-trim <bag> <str>)  TRIM THE RIGHT END OF A STRING
  2384. X            <bag>       a string containing characters to trim
  2385. X            <str>       the string to trim
  2386. X            returns     a trimed copy of the string
  2387. X
  2388. X        (string-upcase <str> &key :start :end)  CONVERT TO UPPERCASE
  2389. X            <str>       the string
  2390. X            :start      the starting offset
  2391. X            :end        the ending offset + 1
  2392. X            returns     a converted copy of the string
  2393. X
  2394. X        (string-downcase <str> &key :start :end)  CONVERT TO LOWERCASE
  2395. X            <str>       the string
  2396. X            :start      the starting offset
  2397. X            :end        the ending offset + 1
  2398. X            returns     a converted copy of the string
  2399. X
  2400. X        (nstring-upcase <str> &key :start :end)  CONVERT TO UPPERCASE
  2401. X            <str>       the string
  2402. X            :start      the starting offset
  2403. X            :end        the ending offset + 1
  2404. X            returns     the converted string (not a copy)
  2405. X
  2406. X        (nstring-downcase <str> &key :start :end)  CONVERT TO LOWERCASE
  2407. X            <str>       the string
  2408. X            :start      the starting offset
  2409. X            :end        the ending offset + 1
  2410. X            returns     the converted string (not a copy)
  2411. X
  2412. X        (strcat <expr>...)  CONCATENATE STRINGS
  2413. X            <expr>      the strings to concatenate
  2414. X            returns     the result of concatenating the strings
  2415. X
  2416. X        (subseq <string> <start> [<end>]) EXTRACT A SUBSTRING
  2417. X            <string>    the string
  2418. X            <start>     the starting position (zero origin)
  2419. X            <end>       the ending position + 1 (defaults to end)
  2420. X            returns     substring between <start> and <end>
  2421. X
  2422. X
  2423. X
  2424. X
  2425. X
  2426. X
  2427. X
  2428. X
  2429. X
  2430. X        XLISP                   STRING FUNCTIONS                 Page 38
  2431. X
  2432. X
  2433. X        (string< <str1> <str2> &key :start1 :end1 :start2 :end2)
  2434. X        (string<= <str1> <str2> &key :start1 :end1 :start2 :end2)
  2435. X        (string= <str1> <str2> &key :start1 :end1 :start2 :end2)
  2436. X        (string/= <str1> <str2> &key :start1 :end1 :start2 :end2)
  2437. X        (string>= <str1> <str2> &key :start1 :end1 :start2 :end2)
  2438. X        (string> <str1> <str2> &key :start1 :end1 :start2 :end2)
  2439. X            <str1>      the first string to compare
  2440. X            <str2>      the second string to compare
  2441. X            :start1     first substring starting offset
  2442. X            :end1       first substring ending offset + 1
  2443. X            :start2     second substring starting offset
  2444. X            :end2       second substring ending offset + 1
  2445. X            returns     t if predicate is true, nil otherwise
  2446. X          Note: case is significant with these comparison functions.
  2447. X
  2448. X        (string-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2449. X        (string-not-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2450. X        (string-equalp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2451. X        (string-not-equalp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2452. X        (string-not-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2453. X        (string-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2454. X            <str1>      the first string to compare
  2455. X            <str2>      the second string to compare
  2456. X            :start1     first substring starting offset
  2457. X            :end1       first substring ending offset + 1
  2458. X            :start2     second substring starting offset
  2459. X            :end2       second substring ending offset + 1
  2460. X            returns     t if predicate is true, nil otherwise
  2461. X          Note: case is not significant with these comparison functions.
  2462. X
  2463. X
  2464. X
  2465. X
  2466. X
  2467. X
  2468. X
  2469. X
  2470. X
  2471. X
  2472. X
  2473. X
  2474. X
  2475. X
  2476. X
  2477. X
  2478. X
  2479. X
  2480. X
  2481. X
  2482. X
  2483. X
  2484. X
  2485. X
  2486. X
  2487. X
  2488. X
  2489. X
  2490. X
  2491. X
  2492. X
  2493. X
  2494. X
  2495. X
  2496. X        XLISP                 CHARACTER FUNCTIONS                Page 39
  2497. X
  2498. X
  2499. X        CHARACTER FUNCTIONS
  2500. X
  2501. X        (char <string> <index>)  EXTRACT A CHARACTER FROM A STRING
  2502. X            <string>    the string
  2503. X            <index>     the string index (zero relative)
  2504. X            returns     the ascii code of the character
  2505. X
  2506. X        (upper-case-p <chr>)  IS THIS AN UPPER CASE CHARACTER?
  2507. X            <chr>       the character
  2508. X            returns     true if the character is upper case, nil otherwise
  2509. X
  2510. X        (lower-case-p <chr>)  IS THIS A LOWER CASE CHARACTER?
  2511. X            <chr>       the character
  2512. X            returns     true if the character is lower case, nil otherwise
  2513. X
  2514. X        (both-case-p <chr>)  IS THIS AN ALPHABETIC (EITHER CASE) CHARACTER?
  2515. X            <chr>       the character
  2516. X            returns     true if the character is alphabetic, nil otherwise
  2517. X
  2518. X        (digit-char-p <chr>)  IS THIS A DIGIT CHARACTER?
  2519. X            <chr>       the character
  2520. X            returns     the digit weight if character is a digit, nil otherwise
  2521. X
  2522. X        (char-code <chr>)  GET THE ASCII CODE OF A CHARACTER
  2523. X            <chr>       the character
  2524. X            returns     the ASCII character code (integer)
  2525. X
  2526. X        (code-char <code>)  GET THE CHARACTER WITH A SPECFIED ASCII CODE
  2527. X            <code>      the ASCII code (integer)
  2528. X            returns     the character with that code or nil
  2529. X
  2530. X        (char-upcase <chr>)  CONVERT A CHARACTER TO UPPER CASE
  2531. X            <chr>       the character
  2532. X            returns     the upper case character
  2533. X
  2534. X        (char-downcase <chr>)  CONVERT A CHARACTER TO LOWER CASE
  2535. X            <chr>       the character
  2536. X            returns     the lower case character
  2537. X
  2538. X        (digit-char <n>)  CONVERT A DIGIT WEIGHT TO A DIGIT
  2539. X            <n>         the digit weight (integer)
  2540. X            returns     the digit character or nil
  2541. X
  2542. X        (char-int <chr>) CONVERT A CHARACTER TO AN INTEGER
  2543. X            <chr>       the character
  2544. X            returns     the ASCII character code
  2545. X
  2546. X        (int-char <int>) CONVERT AN INTEGER TO A CHARACTER
  2547. X            <int>       the ASCII character code
  2548. X            returns     the character with that code
  2549. X
  2550. X
  2551. X
  2552. X
  2553. X
  2554. X
  2555. X
  2556. X
  2557. X
  2558. X
  2559. X
  2560. X
  2561. X
  2562. X        XLISP                 CHARACTER FUNCTIONS                Page 40
  2563. X
  2564. X
  2565. X        (char< <chr1> <chr2>...)
  2566. X        (char<= <chr1> <chr2>...)
  2567. X        (char= <chr1> <chr2>...)
  2568. X        (char/= <chr1> <chr2>...)
  2569. X        (char>= <chr1> <chr2>...)
  2570. X        (char> <chr1> <chr2>...)
  2571. X            <chr1>      the first character to compare
  2572. X            <chr2>      the second character(s) to compare
  2573. X            returns     t if predicate is true, nil otherwise
  2574. X          Note: case is significant with these comparison functions.
  2575. X
  2576. X        (char-lessp <chr1> <chr2>...)
  2577. X        (char-not-greaterp <chr1> <chr2>...)
  2578. X        (char-equalp <chr1> <chr2>...)
  2579. X        (char-not-equalp <chr1> <chr2>...)
  2580. X        (char-not-lessp <chr1> <chr2>...)
  2581. X        (char-greaterp <chr1> <chr2>...)
  2582. X            <chr1>      the first string to compare
  2583. X            <chr2>      the second string(s) to compare
  2584. X            returns     t if predicate is true, nil otherwise
  2585. X          Note: case is not significant with these comparison functions.
  2586. X
  2587. X
  2588. X
  2589. X
  2590. X
  2591. X
  2592. X
  2593. X
  2594. X
  2595. X
  2596. X
  2597. X
  2598. X
  2599. X
  2600. X
  2601. X
  2602. X
  2603. X
  2604. X
  2605. X
  2606. X
  2607. X
  2608. X
  2609. X
  2610. X
  2611. X
  2612. X
  2613. X
  2614. X
  2615. X
  2616. X
  2617. X
  2618. X
  2619. X
  2620. X
  2621. X
  2622. X
  2623. X
  2624. X
  2625. X
  2626. X
  2627. X
  2628. X        XLISP                INPUT/OUTPUT FUNCTIONS              Page 41
  2629. X
  2630. X
  2631. X        INPUT/OUTPUT FUNCTIONS
  2632. X
  2633. X        (read [<stream> [<eof> [<rflag>]]])  READ AN EXPRESSION
  2634. X            <stream>    the input stream (default is standard input)
  2635. X            <eof>       the value to return on end of file (default is nil)
  2636. X            <rflag>     recursive read flag (default is nil)
  2637. X            returns     the expression read
  2638. X
  2639. X        (print <expr> [<stream>])  PRINT AN EXPRESSION ON A NEW LINE
  2640. X            <expr>      the expression to be printed
  2641. X            <stream>    the output stream (default is standard output)
  2642. X            returns     the expression
  2643. X
  2644. X        (prin1 <expr> [<stream>])  PRINT AN EXPRESSION
  2645. X            <expr>      the expression to be printed
  2646. X            <stream>    the output stream (default is standard output)
  2647. X            returns     the expression
  2648. X
  2649. X        (princ <expr> [<stream>])  PRINT AN EXPRESSION WITHOUT QUOTING
  2650. X            <expr>      the expressions to be printed
  2651. X            <stream>    the output stream (default is standard output)
  2652. X            returns     the expression
  2653. X
  2654. X        (pprint <expr> [<stream>])  PRETTY PRINT AN EXPRESSION
  2655. X            <expr>      the expressions to be printed
  2656. X            <stream>    the output stream (default is standard output)
  2657. X            returns     the expression
  2658. X
  2659. X        (terpri [<stream>])  TERMINATE THE CURRENT PRINT LINE
  2660. X            <stream>    the output stream (default is standard output)
  2661. X            returns     nil
  2662. X
  2663. X        (flatsize <expr>)  LENGTH OF PRINTED REPRESENTATION USING PRIN1
  2664. X            <expr>      the expression
  2665. X            returns     the length
  2666. X
  2667. X        (flatc <expr>)  LENGTH OF PRINTED REPRESENTATION USING PRINC
  2668. X            <expr>      the expression
  2669. X            returns     the length
  2670. X
  2671. X
  2672. X
  2673. X
  2674. X
  2675. X
  2676. X
  2677. X
  2678. X
  2679. X
  2680. X
  2681. X
  2682. X
  2683. X
  2684. X
  2685. X
  2686. X
  2687. X
  2688. X
  2689. X
  2690. X
  2691. X
  2692. X
  2693. X
  2694. X        XLISP                 THE FORMAT FUNCTION                Page 42
  2695. X
  2696. X
  2697. X        THE FORMAT FUNCTION
  2698. X
  2699. X        (format <stream> <fmt> <arg>...)  DO FORMATTED OUTPUT
  2700. X            <stream>    the output stream
  2701. X            <fmt>       the format string
  2702. X            <arg>       the format arguments
  2703. X            returns     output string if <stream> is nil, nil otherwise
  2704. X
  2705. X        The format string can contain characters that should be copied
  2706. X        directly to the output and formatting directives.  The
  2707. X        formatting directives are:
  2708. X
  2709. X            ~A          print next argument using princ
  2710. X            ~S          print next argument using prin1
  2711. X            ~%          start a new line
  2712. X            ~~          print a tilde character
  2713. X
  2714. X
  2715. X
  2716. X
  2717. X
  2718. X
  2719. X
  2720. X
  2721. X
  2722. X
  2723. X
  2724. X
  2725. X
  2726. X
  2727. X
  2728. X
  2729. X
  2730. X
  2731. X
  2732. X
  2733. X
  2734. X
  2735. X
  2736. X
  2737. X
  2738. X
  2739. X
  2740. X
  2741. X
  2742. X
  2743. X
  2744. X
  2745. X
  2746. X
  2747. X
  2748. X
  2749. X
  2750. X
  2751. X
  2752. X
  2753. X
  2754. X
  2755. X
  2756. X
  2757. X
  2758. X
  2759. X
  2760. X        XLISP                  FILE I/O FUNCTIONS                Page 43
  2761. X
  2762. X
  2763. X        FILE I/O FUNCTIONS
  2764. X
  2765. X        (open <fname> &key :direction)  OPEN A FILE STREAM
  2766. X            <fname>     the file name string or symbol
  2767. X            :direction  :input or :output (default is :input)
  2768. X            returns     a stream
  2769. X
  2770. X        (close <stream>)  CLOSE A FILE STREAM
  2771. X            <stream>    the stream
  2772. X            returns     nil
  2773. X
  2774. X        (read-char [<stream>])  READ A CHARACTER FROM A STREAM
  2775. X            <stream>    the input stream (default is standard input)
  2776. X            returns     the character
  2777. X
  2778. X        (peek-char [<flag> [<stream>]])  PEEK AT THE NEXT CHARACTER
  2779. X            <flag>      flag for skipping white space (default is nil)
  2780. X            <stream>    the input stream (default is standard input)
  2781. X            returns     the character (integer)
  2782. X
  2783. X        (write-char <ch> [<stream>])  WRITE A CHARACTER TO A STREAM
  2784. X            <ch>        the character to write
  2785. X            <stream>    the output stream (default is standard output)
  2786. X            returns     the character
  2787. X
  2788. X        (read-line [<stream>])  READ A LINE FROM A STREAM
  2789. X            <stream>    the input stream (default is standard input)
  2790. X            returns     the string
  2791. X
  2792. X        (read-byte [<stream>])  READ A BYTE FROM A STREAM
  2793. X            <stream>    the input stream (default is standard input)
  2794. X            returns     the byte (integer)
  2795. X
  2796. X        (write-byte <byte> [<stream>])  WRITE A BYTE TO A STREAM
  2797. X            <byte>      the byte to write (integer)
  2798. X            <stream>    the output stream (default is standard output)
  2799. X            returns     the byte (integer)
  2800. X
  2801. X
  2802. X
  2803. X
  2804. X
  2805. X
  2806. X
  2807. X
  2808. X
  2809. X
  2810. X
  2811. X
  2812. X
  2813. X
  2814. X
  2815. X
  2816. X
  2817. X
  2818. X
  2819. X
  2820. X
  2821. X
  2822. X
  2823. X
  2824. X
  2825. X
  2826. X        XLISP               STRING STREAM FUNCTIONS              Page 44
  2827. X
  2828. X
  2829. X        STRING STREAM FUNCTIONS
  2830. X
  2831. X        These functions operate on unnamed streams.  An unnamed output
  2832. X        stream collects characters sent to it when it is used as the
  2833. X        destination of any output function.  The functions 'get-output-
  2834. X        stream-string' and string or a list of characters.
  2835. X
  2836. X        An unnamed input stream is setup with the 'make-string-input-
  2837. X        stream' function and returns each character of the string when
  2838. X        it is used as the source of any input function.
  2839. X
  2840. X        (make-string-input-stream <str> [<start> [<end>]])
  2841. X            <str>       the string
  2842. X            <start>     the starting offset
  2843. X            <end>       the ending offset + 1
  2844. X            returns     an unnamed stream that reads from the string
  2845. X
  2846. X        (make-string-output-stream)
  2847. X            returns     an unnamed output stream
  2848. X
  2849. X        (get-output-stream-string <stream>)
  2850. X            <stream>    the output stream
  2851. X            returns     the output so far as a string
  2852. X          Note:  the output stream is emptied by this function
  2853. X
  2854. X        (get-output-stream-list <stream>)
  2855. X            <stream>    the output stream
  2856. X            returns     the output so far as a list
  2857. X          Note:  the output stream is emptied by this function
  2858. X
  2859. X
  2860. X
  2861. X
  2862. X
  2863. X
  2864. X
  2865. X
  2866. X
  2867. X
  2868. X
  2869. X
  2870. X
  2871. X
  2872. X
  2873. X
  2874. X
  2875. X
  2876. X
  2877. X
  2878. X
  2879. X
  2880. X
  2881. X
  2882. X
  2883. X
  2884. X
  2885. X
  2886. X
  2887. X
  2888. X
  2889. X
  2890. X
  2891. X
  2892. X        XLISP                   SYSTEM FUNCTIONS                 Page 45
  2893. X
  2894. X
  2895. X        SYSTEM FUNCTIONS
  2896. X
  2897. X        (load <fname> &key :verbose :print)  LOAD A SOURCE FILE
  2898. X            <fname>     the filename string or symbol
  2899. X            :verbose    the verbose flag (default is t)
  2900. X            :print      the print flag (default is nil)
  2901. X            returns     the filename
  2902. X
  2903. X        (save <fname>) SAVE WORKSPACE TO A FILE
  2904. X            <fname>     the filename string or symbol
  2905. X            returns     t if workspace was written, nil otherwise
  2906. X
  2907. X        (restore <fname>) RESTORE WORKSPACE FROM A FILE
  2908. X            <fname>     the filename string or symbol
  2909. X            returns     nil on failure, otherwise never returns
  2910. X
  2911. X        (dribble [<fname>])  CREATE A FILE WITH A TRANSCRIPT OF A SESSION
  2912. X            <fname>     file name string or symbol
  2913. X                        (if missing, close current transcript)
  2914. X            returns     t if the transcript is opened, nil if it is closed
  2915. X
  2916. X        (gc)  FORCE GARBAGE COLLECTION
  2917. X            returns     nil
  2918. X
  2919. X        (expand <num>)  EXPAND MEMORY BY ADDING SEGMENTS
  2920. X            <num>       the number of segments to add
  2921. X            returns     the number of segments added
  2922. X
  2923. X        (alloc <num>)  CHANGE NUMBER OF NODES TO ALLOCATE IN EACH SEGMENT
  2924. X            <num>       the number of nodes to allocate
  2925. X            returns     the old number of nodes to allocate
  2926. X
  2927. X        (room)  SHOW MEMORY ALLOCATION STATISTICS
  2928. X            returns     nil
  2929. X
  2930. X        (type-of <expr>)  RETURNS THE TYPE OF THE EXPRESSION
  2931. X            <expr>      the expression to return the type of
  2932. X            returns     nil if the value is nil otherwise one of the symbols:
  2933. X                          SYMBOL          for symbols
  2934. X                          OBJECT          for objects
  2935. X                          CONS            for conses
  2936. X                          SUBR            for built-in functions
  2937. X                          FSUBR           for special forms
  2938. X                          CLOSURE         for defined functions
  2939. X                          STRING          for strings
  2940. X                          FIXNUM          for integers
  2941. X                          FLONUM          for floating point numbers
  2942. X                          CHARACTER       for characters
  2943. X                          FILE-STREAM     for file pointers
  2944. X                          UNNAMED-STREAM  for unnamed streams
  2945. X                          ARRAY           for arrays
  2946. X
  2947. X
  2948. X
  2949. X
  2950. X
  2951. X
  2952. X
  2953. X
  2954. X
  2955. X
  2956. X
  2957. X
  2958. X        XLISP                   SYSTEM FUNCTIONS                 Page 46
  2959. X
  2960. X
  2961. X        (peek <addrs>)  PEEK AT A LOCATION IN MEMORY
  2962. X            <addrs>     the address to peek at (integer)
  2963. X            returns     the value at the specified address (integer)
  2964. X
  2965. X        (poke <addrs> <value>)  POKE A VALUE INTO MEMORY
  2966. X            <addrs>     the address to poke (integer)
  2967. X            <value>     the value to poke into the address (integer)
  2968. X            returns     the value
  2969. X
  2970. X        (address-of <expr>)  GET THE ADDRESS OF AN XLISP NODE
  2971. X            <expr>      the node
  2972. X            returns     the address of the node (integer)
  2973. X
  2974. X        (exit)  EXIT XLISP
  2975. X            returns     never returns
  2976. X
  2977. X
  2978. X
  2979. X
  2980. X
  2981. X
  2982. X
  2983. X
  2984. X
  2985. X
  2986. X
  2987. X
  2988. X
  2989. X
  2990. X
  2991. X
  2992. X
  2993. X
  2994. X
  2995. X
  2996. X
  2997. X
  2998. X
  2999. X
  3000. X
  3001. X
  3002. X
  3003. X
  3004. X
  3005. X
  3006. X
  3007. X
  3008. X
  3009. X
  3010. X
  3011. X
  3012. X
  3013. X
  3014. X
  3015. X
  3016. X
  3017. X
  3018. X
  3019. X
  3020. X
  3021. X
  3022. X
  3023. X
  3024. X        XLISP                       EXAMPLES                     Page 47
  3025. X
  3026. X
  3027. X        FILE I/O FUNCTIONS
  3028. X
  3029. X        Input from a File
  3030. X
  3031. X        To open a file for input, use the OPEN function with the keyword
  3032. X        argument :DIRECTION set to :INPUT.  To open a file for output,
  3033. X        use the OPEN function with the keyword argument :DIRECTION set
  3034. X        to :OUTPUT.  The OPEN function takes a single required argument
  3035. X        which is the name of the file to be opened.  This name can be in
  3036. X        the form of a string or a symbol.  The OPEN function returns an
  3037. X        object of type FILE-STREAM if it succeeds in opening the
  3038. X        specified file.  It returns the value NIL if it fails.  In order
  3039. X        to manipulate the file, it is necessary to save the value
  3040. X        returned by the OPEN function.  This is usually done by
  3041. X        assigning it to a variable with the SETQ special form or by
  3042. X        binding it using LET or LET*.  Here is an example:
  3043. X
  3044. X            (setq fp (open "init.lsp" :direction :input))
  3045. X
  3046. X        Evaluating this expression will result in the file "init.lsp"
  3047. X        being opened.  The file object that will be returned by the OPEN
  3048. X        function will be assigned to the variable "fp".
  3049. X
  3050. X        It is now possible to use the file for input.  To read an
  3051. X        expression from the file, just supply the value of the "fp"
  3052. X        variable as the optional "stream" argument to READ.
  3053. X
  3054. X            (read fp)
  3055. X
  3056. X        Evaluating this expression will result in reading the first
  3057. X        expression from the file "init.lsp".  The expression will be
  3058. X        returned as the result of the READ function.  More expressions
  3059. X        can be read from the file using further calls to the READ
  3060. X        function.  When there are no more expressions to read, the READ
  3061. X        function will return NIL (or whatever value was supplied as the
  3062. X        second argument to READ).
  3063. X
  3064. X        Once you are done reading from the file, you should close it.
  3065. X        To close the file, use the following expression:
  3066. X
  3067. X            (close fp)
  3068. X
  3069. X        Evaluating this expression will cause the file to be closed.
  3070. X
  3071. X
  3072. X
  3073. X
  3074. X
  3075. X
  3076. X
  3077. X
  3078. X
  3079. X
  3080. X
  3081. X
  3082. X
  3083. X
  3084. X
  3085. X
  3086. X
  3087. X
  3088. X
  3089. X
  3090. X        XLISP                       EXAMPLES                     Page 48
  3091. X
  3092. X
  3093. X        Output to a File
  3094. X
  3095. X        Writing to a file is pretty much the same as reading from one.
  3096. X        You need to open the file first.  This time you should use the
  3097. X        OPEN function to indicate that you will do output to the file.
  3098. X        For example:
  3099. X
  3100. X            (setq fp (open "test.dat" :direction :output))
  3101. X
  3102. X        Evaluating this expression will open the file "test.dat" for
  3103. X        output.  If the file already exists, its current contents will
  3104. X        be discarded.  If it doesn't already exist, it will be created.
  3105. X        In any case, a FILE-STREAM object will be returned by the OPEN
  3106. X        function.  This file object will be assigned to the "fp"
  3107. X        variable.
  3108. X
  3109. X        It is now possible to write to this file by supplying the value
  3110. X        of the "fp" variable as the optional "stream" parameter in the
  3111. X        PRINT function.
  3112. X
  3113. X            (print "Hello there" fp)
  3114. X
  3115. X        Evaluating this expression will result in the string "Hello
  3116. X        there" being written to the file "test.dat".  More data can be
  3117. X        written to the file using the same technique.
  3118. X
  3119. X        Once you are done writing to the file, you should close it.
  3120. X        Closing an output file is just like closing an input file.
  3121. X
  3122. X            (close fp)
  3123. X
  3124. X        Evaluating this expression will close the output file and make
  3125. X        it permanent.
  3126. X
  3127. X
  3128. X
  3129. X
  3130. X
  3131. X
  3132. X
  3133. X
  3134. X
  3135. X
  3136. X
  3137. X
  3138. X
  3139. X
  3140. X
  3141. X
  3142. X
  3143. X
  3144. X
  3145. X
  3146. X
  3147. X
  3148. X
  3149. X
  3150. X
  3151. X
  3152. X
  3153. X
  3154. X
  3155. X
  3156. X        XLISP                       EXAMPLES                     Page 49
  3157. X
  3158. X
  3159. X        A Slightly More Complicated File Example
  3160. X
  3161. X        This example shows how to open a file, read each Lisp expression
  3162. X        from the file and print it.  It demonstrates the use of files
  3163. X        and the use of the optional "stream" argument to the READ
  3164. X        function.
  3165. X
  3166. X            (do* ((fp (open "test.dat" :direction :input))
  3167. X                  (ex (read fp) (read fp)))
  3168. X                 ((null ex) nil)
  3169. X              (print ex))
  3170. X
  3171. X
  3172. X
  3173. X
  3174. X
  3175. X
  3176. X
  3177. X
  3178. X
  3179. X
  3180. X
  3181. X
  3182. X
  3183. X
  3184. X
  3185. X
  3186. X
  3187. X
  3188. X
  3189. X
  3190. X
  3191. X
  3192. X
  3193. X
  3194. X
  3195. X
  3196. X
  3197. X
  3198. X
  3199. X
  3200. X
  3201. X
  3202. X
  3203. X
  3204. X
  3205. X
  3206. X
  3207. X
  3208. X
  3209. X
  3210. X
  3211. X
  3212. X
  3213. X
  3214. X
  3215. X
  3216. X
  3217. X
  3218. X
  3219. X
  3220. X
  3221. X
  3222. X
  3223. X
  3224. X
  3225. X
  3226. X
  3227. X
  3228. X
  3229. X
  3230. X
  3231. X
  3232. X
  3233. X
  3234. X
  3235. X
  3236. X
  3237. X
  3238. X
  3239. X
  3240. X
  3241. X
  3242. X
  3243. X
  3244. X
  3245. X
  3246. X
  3247. X
  3248. X
  3249. X
  3250. X
  3251. X
  3252. X
  3253. X
  3254. X
  3255. X
  3256. X
  3257. X
  3258. X
  3259. X
  3260. X
  3261. X
  3262. X
  3263. X
  3264. X
  3265. X
  3266. SHAR_EOF
  3267. if test 80928 -ne "`wc -c 'xlisp.doc'`"
  3268. then
  3269.     echo shar: error transmitting "'xlisp.doc'" '(should have been 80928 characters)'
  3270. fi
  3271. #    End of shell archive
  3272. exit 0
  3273. -- 
  3274. Gary Murphy                   uunet!mitel!sce!cognos!garym
  3275.                               (garym%cognos.uucp@uunet.uu.net)
  3276. (613) 738-1338 x5537          Cognos Inc. P.O. Box 9707 Ottawa K1G 3N3
  3277. "There are many things which do not concern the process" - Joan of Arc
  3278.  
  3279.